Simple program to allow user to input weight in pounds or Kg and then print weight in Kg. The below code gives error: "Type '()' cannot conform to 'View'. Any help is greatly appreciated.
inline-codeimport SwiftUI".
struct ContentView: View {
@State private var weight = 175.0
@State private var weightKg = 0.0
@State private var ifPounds: Bool = true
var body: some View {
VStack {
HStack {
Text("Select unit for weight:")
Toggle("", isOn: $ifPounds)
.labelsHidden()
.background(Color.green)
.clipShape(Capsule())
Text(ifPounds ? "Pounds" : "Kg")
.padding()
} // HStack
if (ifPounds == true) {
weightKg = weight/2.205
} else {
weightKg = weight
}
Text("Your weight is \(weightKg, specifier: "%.1f") ")
} //Vtack
} //Some View
} //Content View
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Post
Replies
Boosts
Views
Activity
Convolving a signal array (yData) with a filter array (gausData). The filter works as expected. But vDSP_convD returns the convolved array (correlationResult) truncated by the number of elements in the filter array, plus one. My question is, are the truncated points removed from the end of the signal array? Not clear from Apple's description.
vDSP_convD( yData, 1, gausData, 1, &correlationResult, 1, vDSP_Length(yData.count - 5_000 + 1), vDSP_Length(gausData.count) )
code-block
Simple LineMark plot (macOS), but the ydata-array has 100,000 points. Need to include most of the data points as there is fine structure. When I print the Xvalue and Yvalue to the console, there is minimal lag. But when I use Text to display Xvalue and Yvalue in the view, the lag is significant. I understand that the X- and Y-values are wrapped in an @State and cause the view to update whenever they change. Is there a way to "decouple" the Xvalue and Yvalue such that they do not cause the view to update, but still display in a view? Note that the chart does not change during DragGesture.
import SwiftUI
import Charts
struct ContentView: View {
@State private var Xvalue: Int = 0
@State private var Yvalue: Int = 0
var body: some View {
NavigationSplitView {
Text(String("X: \(Xvalue), Y: \(Yvalue)")) /* This Text bogs down with DragGesture */
}
detail: {
Chart(0..<ydata.count, id: \.self) { index in
LineMark(
x: .value("X-axis", index),
y: .value("Y-axis", ydata[index])
)
}
.chartOverlay { proxy in
GeometryReader { geometry in
Rectangle().fill(.clear).contentShape(Rectangle())
.gesture(
DragGesture()
.onChanged { value in
// Convert the gesture location to the coordiante space of the plot area.
let origin = geometry[proxy.plotAreaFrame].origin
let location = CGPoint(
x: value.location.x - origin.x,
y: value.location.y - origin.y
)
// Get the x and y values from the location.
let XYvalue = proxy.value(at: location, as: ((Int, Int).self))
Xvalue = XYvalue!.0
Yvalue = XYvalue!.1
print(Xvalue, Yvalue) /* This printout can keep up with DragGesture */
}
)
}
}
}
}
}
My SwiftUI code runs fine on macOS, iOS(iPad) and larger iPhones, but will not display the detail view on smaller iPhones.
Is there a way to force the smaller iPhones to display the detail view?
And if not,
When I put the App on the Apple store, for sale, will the Apple store be smart enough to flag the App as not appropriate for smaller iPhones, such as the SE (2nd and 3rd gen.) and prevent downloads?
Thanks in advance for any guidance.