Post

Replies

Boosts

Views

Activity

Reply to How to make an updatable ForEach loop SwiftUI
When I start the app there's only one "hey" and no more will show up when I add more flags. No, you get 2 heys, as explained by @B347 What you want is not clear at all. what do you expect to get ? display text per child: where are the children defined ? where and how do you add flags ? In any case, if you want view to be updated, flags should be a State var. An advice: study an Apple tutorial on Swift and SwiftUI. It seems there are some basics you are still missing.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’24
Reply to Inserting array of model objects using modelContext
AFAIK, there is not. But it is really easy to build it (even as extension) by calling insert in a loop on all objects. Get some additional advice here for performance optimisation: https://stackoverflow.com/questions/77533881/how-do-you-insert-an-array-of-objects-into-the-swiftdata-modelcontext modelContext.transaction { for obj in objects { modelContext.insert(obj) } do { try modelContext.save() } catch { // Handle error } }
Topic: App & System Services SubTopic: iCloud Tags:
Sep ’24
Reply to Copy Creation when we pass primitive type such as Int to a Swift Function.
If you want to pass a reference, to be able to modify the parameter, you have to use inout. public func Test (_ pValue : inout Int) { print ("on call", pValue) pValue += 10 } var x : Int = 2 // Must be a var ; // with let, would get a compile error: // Cannot pass immutable value as inout argument: 'x' is a 'let' constant Test (&x) print ("after call", x) You get: on call 2 after call 12
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’24
Reply to Button with symbol SF design like Apple
I'm not entirely satisfied with the outcome of this code. What is not satisfying ? What do you get ? What do you expect exactly ? Why don't you apply the opacity to the background of the icon ? Note that if you could not publish such an app on the AppStore if you copy an Apple icon.
Topic: Design SubTopic: General Tags:
Sep ’24
Reply to App is too minimal?
A definition of minimal was that if it can be a web site, then it is probably under limit. Guideline 4.2 Minimum Functionality Your app should include features, content, and UI that elevate it beyond a repackaged website. If your app is not particularly useful, unique, or “app-like,” it doesn’t belong on the App Store. If your App doesn’t provide some sort of lasting entertainment value or adequate utility, it may not be accepted. If I understand correctly, that's the case for your app. That does not mean it is not useful but is not rich enough to be in the Appstore. So you have 2 options: stay as a web site (or a web app) enrich your app to provide some sort of lasting entertainment value and exploit specific features of iPhone (eg: showing the results in the Dynamic Island). A good tag would be "App Review "
Topic: Design SubTopic: General Tags:
Sep ’24
Reply to SwiftUI Picker not trigger `onChange` first time when inside Menu in MacOS
There is effectively something weird here. At first change, Picker does not react. That seems to be an old bug (or undocumented behaviour): https://forums.developer.apple.com/forums/thread/688685 In addition of the solution you found, I implemented the Spacer().onChange trick and it works: struct swiftuiTestApp: App { @State private var value = "a" var body: some Scene { WindowGroup { Menu("menu \(value)") { Picker("", selection: $value) { Text("A").tag("a") Text("B").tag("b") Text("C").tag("c") } .pickerStyle(.inline) .onChange(of: value) { oldValue, newValue in print("onChange", oldValue, newValue) } } Spacer().onChange(of: value) { oldValue, newValue in print("Spacer onChange", oldValue, newValue) } } } } Here is the log: Spacer onChange a b // First change does not trigger picker onChange, but triggers Spacer() Spacer onChange b c // next change does trigger picker onChange, and Spacer() onChange b c You should file a bug report.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’24
Reply to How to make an updatable ForEach loop SwiftUI
When I start the app there's only one "hey" and no more will show up when I add more flags. No, you get 2 heys, as explained by @B347 What you want is not clear at all. what do you expect to get ? display text per child: where are the children defined ? where and how do you add flags ? In any case, if you want view to be updated, flags should be a State var. An advice: study an Apple tutorial on Swift and SwiftUI. It seems there are some basics you are still missing.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’24
Reply to Inserting array of model objects using modelContext
AFAIK, there is not. But it is really easy to build it (even as extension) by calling insert in a loop on all objects. Get some additional advice here for performance optimisation: https://stackoverflow.com/questions/77533881/how-do-you-insert-an-array-of-objects-into-the-swiftdata-modelcontext modelContext.transaction { for obj in objects { modelContext.insert(obj) } do { try modelContext.save() } catch { // Handle error } }
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Sep ’24
Reply to Copy Creation when we pass primitive type such as Int to a Swift Function.
If you want to pass a reference, to be able to modify the parameter, you have to use inout. public func Test (_ pValue : inout Int) { print ("on call", pValue) pValue += 10 } var x : Int = 2 // Must be a var ; // with let, would get a compile error: // Cannot pass immutable value as inout argument: 'x' is a 'let' constant Test (&x) print ("after call", x) You get: on call 2 after call 12
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’24
Reply to Button with symbol SF design like Apple
I'm not entirely satisfied with the outcome of this code. What is not satisfying ? What do you get ? What do you expect exactly ? Why don't you apply the opacity to the background of the icon ? Note that if you could not publish such an app on the AppStore if you copy an Apple icon.
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Sep ’24
Reply to App is too minimal?
A definition of minimal was that if it can be a web site, then it is probably under limit. Guideline 4.2 Minimum Functionality Your app should include features, content, and UI that elevate it beyond a repackaged website. If your app is not particularly useful, unique, or “app-like,” it doesn’t belong on the App Store. If your App doesn’t provide some sort of lasting entertainment value or adequate utility, it may not be accepted. If I understand correctly, that's the case for your app. That does not mean it is not useful but is not rich enough to be in the Appstore. So you have 2 options: stay as a web site (or a web app) enrich your app to provide some sort of lasting entertainment value and exploit specific features of iPhone (eg: showing the results in the Dynamic Island). A good tag would be "App Review "
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Sep ’24
Reply to SwiftUI Picker not trigger `onChange` first time when inside Menu in MacOS
There is effectively something weird here. At first change, Picker does not react. That seems to be an old bug (or undocumented behaviour): https://forums.developer.apple.com/forums/thread/688685 In addition of the solution you found, I implemented the Spacer().onChange trick and it works: struct swiftuiTestApp: App { @State private var value = "a" var body: some Scene { WindowGroup { Menu("menu \(value)") { Picker("", selection: $value) { Text("A").tag("a") Text("B").tag("b") Text("C").tag("c") } .pickerStyle(.inline) .onChange(of: value) { oldValue, newValue in print("onChange", oldValue, newValue) } } Spacer().onChange(of: value) { oldValue, newValue in print("Spacer onChange", oldValue, newValue) } } } } Here is the log: Spacer onChange a b // First change does not trigger picker onChange, but triggers Spacer() Spacer onChange b c // next change does trigger picker onChange, and Spacer() onChange b c You should file a bug report.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’24