Post

Replies

Boosts

Views

Activity

PreviewProvider view initializer compiler error with @Binding
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?
4
2
2.7k
Mar ’22
How to use ForEach to increase number of rows in SwiftUI's Picker?
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?
3
0
1.4k
Mar ’22
PreviewProvider view initializer compiler error
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?
2
0
349
Mar ’22
Can I prevent users of my app from seeing my full and correct name?
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.
0
0
237
Feb ’22