From my question that was answered here, I'm now not able to figure out how to make Canvas work when there's an @Binding in the struct. My variation is now this toy code:
struct RootView: View {
@Binding var thingToUse: Thing
var body: some View {
// body code that compiles without error
}
}
struct RootView_Previews: PreviewProvider {
static var previews: some View {
var thingToPreview = Thing() // ERROR
RootView(thingToUse: thingToPreview)
}
}
This one gives the error, "Cannot convert value of type 'Thing' to expected argument type 'Binding'". Wrapping the preview's var with @Binding doesn't make sense either. I tried anyway and got, "Cannot declare local wrapped variable in result builder." Other stuff I've tried doesn't compile, which means I still don't fully comprehend the logic here. How do I make that preview compile?
Post
Replies
Boosts
Views
Activity
I found the following code that an expert posted as a solution for allowing arbitrary numbers of rows in a SwiftUI picker:
struct ContentView: View {
var body: some View {
Picker(selection: $value, label: Text("Pick One")) {
ForEach(Array(stride(from: 1000, through: 20000, by: 1000))) { number in
Text("\(number)").tag(number)
}
}
}
@State var value: Int = 1000
}
Adapting it to my use, I got an error. Cutting and pasting the original code gives me the exact same error, "No exact matches in call to initializer" at the ForEach's line.
I can fix the error by changing the ForEach to ForEach(1..<31). However, ForEach(1...31) gives the same error again. Can someone explain these errors?
I'm experienced in many ways, but new to Swift and SwiftUI. After a lot of studying, I've been able to get my little test project going OK, but I've run into a trivial error that I just don't know enough to figure out, and I've tried. I've reduced it to this toy:
import SwiftUI
struct Root {
var register = 3
var degree = 0
}
struct RootView: View {
var rootToView: Root
var body: some View {
Text("[10, 10]")
}
}
struct RootView_Previews: PreviewProvider {
static var previews: some View {
RootView(rootToView: Root) // ERROR
}
}
This gives the compiler error, "Cannot convert value of type 'Root.Type' to expected argument type 'Root'"
My project runs fine in the simulator, but of course I want the Canvas to work, and most importantly, I need to understand what's expected as the argument for RootView in the provider. Can someone please explain?
n00b here. I see lists of EnvironmentValues documented, but not the possible values each one can be set to. For example, verticalSizeLimit can be .compact and .regular, but where are .compact and .regular documented in relation to verticalSizeLimit. Aside from Bools, where are EnvironmentValues' possible values documented?
I want to develop a music-related app for myself to use. A few internet friends may want to try it, and I'm happy to share it for free. Mostly, we don't know each others' actual identities because it's irrelevant. I'm not a professional developer, and I do want to maintain my privacy. I still haven't purchased a developer license from Apple, but if I do, and my app gets listed in the app store someday, will users be able to see my name?
Apple has my identity info because there are good reasons for that, but it looks like at least the name on the account gets published with the app. Is it possible to have the app listed with a fictitious name even though I'm not a business? I mean, if a user ever has a serious issue with me, which is rather unlikely, Apple has all the info necessary to hold me accountable. So I'd rather not publish my name to the world just to share my silly little app with a few people.