Post

Replies

Boosts

Views

Activity

Reply to Question about Xcode
Here is the structure of a project with a Watch companion app (it was created several years ago, with Xcode 9 or 10 probably and uses WatchKit and not SwiftUI): I have highlighted the 3 info.plist the first is the usual for iOS app, in iOS section (bundle display name is 'MyApp') Second in myApp Watch (bundle display name is 'MyApp'). The content is: third info.plist in myApp Watch Extension (bundle display name is 'MyApp Watch extension'). Its content is: Note also infoPlist, which contains some localizations, with keys as CFBundleName, NSCameraUsageDescription I don't remember how they were created (I think it was automatic when creating watch companion, but you can probably recreate manually). Hope that helps.
Aug ’25
Reply to Restricting App Installation to Devices Supporting Apple Intelligence Without Triggering Game Mode
Effectively, exploring what could be done with UIRequiredDeviceCapabilities in Info.plist appears the best option. https://stackoverflow.com/questions/10191657/restrict-to-certain-ios-target-devices-for-app-store-submission May be you can find a listed capability that matches approximately with support of Apple Intelligence. But unfortunately, gaming seems to be the only one to discriminate for A17 chip. https://developer.apple.com/support/required-device-capabilities/
Aug ’25
Reply to why no "fold all" option?
My understanding is it is because folding is multi level. Unfold is easy: everything that was folded, whatever level, will unfold. But folding all: what you you keep ? Just very top level, at class level, where you see nothing more ? At the first level func ? So you should have to specify the level to make it any use. So, imagine what should be the result of a fold all and you may find it is impracticable.
Aug ’25
Reply to @State variable returns empty despite being set in .onAppear function
Finally, to give you in depth explanation about the use of @State in DataView: https://forums.swift.org/t/im-so-confused-why-state-var-inside-a-view-do-not-change-when-you-call-a-method-on-this-view-from-some-outer-view/31944/7 And you can test with a Binding: struct DataView2: View { @Binding var datum: Data2 var body: some View { Text("DataView \(datum.str)") } } calling it with DataView2(datum: $data[index]) Good continuation.
Topic: Design SubTopic: General Tags:
Aug ’25
Reply to @State variable returns empty despite being set in .onAppear function
Finally, to give you in depth explanation about the use of @State in DataView: https://forums.swift.org/t/im-so-confused-why-state-var-inside-a-view-do-not-change-when-you-call-a-method-on-this-view-from-some-outer-view/31944/7 And you can test with a Binding: struct DataView2: View { @Binding var datum: Data2 var body: some View { Text("DataView \(datum.str)") } } calling it with DataView2(datum: $data[index]) Good continuation.
Topic: Design SubTopic: General Tags:
Aug ’25
Reply to @State variable returns empty despite being set in .onAppear function
This cannot compile. data is a constant that you try to modify. let data = try Data(contentsOf: url) let jsonDecoded = try JSONDecoder().decode([Data2].self, from: data) data = jsonDecoded The code I sent was: let dataRead = try Data(contentsOf: url) let jsonDecoded = try JSONDecoder().decode([Data2].self, from: dataRead) data = jsonDecoded With these changes, your code works OK. Could you show the DataView code ?
Topic: Design SubTopic: General Tags:
Aug ’25
Reply to @State variable returns empty despite being set in .onAppear function
Did you change datum to a simple var and not a State var ? Could you show the complete code, to see how Binding is used. Logically, @Binding var index: Int should be in the ContentView and the @State var index = 0 in the other view But I would need to check. PS: don't forget to close the thread, eventually starting a new one where you reference this one.
Topic: Design SubTopic: General Tags:
Aug ’25
Reply to @State variable returns empty despite being set in .onAppear function
Another point. In DataView, index should not be a State variable. Add a button in ContentView VStack { if showView && (index >= 0) && (index < data.count) { DataView(datum: data[index]) } Spacer() HStack { Text("Index: \(index) -> ") Button("Next") { index += 1 if index >= data.count { index = 0 } } } } You will see that text in DataView does not change Text("DataView \(datum.str)") always says DataView String 1 Now change DataView as follows to get it updated on index change by button press: struct DataView: View { /*@State*/ var datum: Data2 var body: some View { Text("DataView \(datum.str)") } } Note: I renamed data to datum for an array item, to differentiate from the array. Now, I have to update my initial answer. In fact, no need for showView and Dispatch (even though that made it work). Just test index: if (index < data.count) { DataView(datum: data[index]) Without the index test, it crashes… Swift/ContiguousArrayBuffer.swift:691: Fatal error: Index out of range Reason is that DataView is not called immediately but only when State var data is populated by getData (then count changes) and has all its elements. So the test has a similar effect as Dispatch to wait for data to be fetched.
Topic: Design SubTopic: General Tags:
Aug ’25
Reply to @State variable returns empty despite being set in .onAppear function
It is a question of timing. When onAppear returns, and DataView is called, the array is not yet populated, even though its count is already OK. You have to wait for a short time in onAppear (0.01 s should be OK). Here is the solution. I had to rename Data to avoid the error above (Data is a Foundation type). I renamed to Data2 struct Data2: Decodable, Hashable { let index: Int let str: String } struct DataView: View { @State var data: Data2 var body: some View { Text("DataView \(data.str)") } } struct ContentView: View { @State var showView = false // To wait for array to be populated before we display the view @State var data: [Data2] @State var index: Int = 0 var body: some View { VStack { if showView { DataView(data: data[index]) // Text("Hello \(data.count)") // To test if needed ; without async, data.count is 2. Seems OK, but… // Text("Hello \(data.count) index \(index) \(data[0].str)") // but without async, it will crash, as data is not populated yet, even if count is already 2 } } .onAppear { let filePath = Bundle.main.path(forResource: "data", ofType: "json") let url = URL(fileURLWithPath: filePath!) data = getData(url: url) DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { // <<-- THE KEY POINT 0.1 sec delay self.showView = true } } } func getData(url: URL) -> [Data2] { do { let data = try Data(contentsOf: url) let jsonDecoded = try JSONDecoder().decode([Data2].self, from: data) return jsonDecoded } catch let error as NSError { print("Fail: \(error.localizedDescription)") } catch { print("Fail: \(error)") } return [] } } Credit: https://stackoverflow.com/questions/62355428/how-do-i-show-a-new-view-after-some-delay-amount-of-time-swiftui A simpler option is to use an init: struct ContentView: View { @State var data: [Data2] @State var index: Int = 0 init() { let filePath = Bundle.main.path(forResource: "data", ofType: "json") let url = URL(fileURLWithPath: filePath!) // data = getData(url: url) // We cannot call getData in init do { let dataRead = try Data(contentsOf: url) let jsonDecoded = try JSONDecoder().decode([Data2].self, from: dataRead) data = jsonDecoded return } catch let error as NSError { print("Fail: \(error.localizedDescription)") } catch { print("Fail: \(error)") } data = [] return } var body: some View { VStack { DataView(data: data[index]) } } }
Topic: Design SubTopic: General Tags:
Aug ’25
Reply to Review is stuck in "In Review" status over than a day — what should I do?
It’s really important for me that the review does not get delayed further. Unfortunately, the forum is not the place to get it accelerated. By experience, the time "in review" can vary largely, from 1 hour to more than a day. I noticed that if there was a previous issue with submission, it can take a bit longer.
Replies
Boosts
Views
Activity
Aug ’25
Reply to why no "fold all" option?
Forum is for technical discussion for those who want to engage in such discussions. Good bye and good continuation so.
Replies
Boosts
Views
Activity
Aug ’25
Reply to why no "fold all" option?
From what I read, looks like it starts by collapsing at the lowest level and to the next if you repeat. But I'm not using Studio, so that's just a guess. In anywise, you could file a bug report asking for evolution.
Replies
Boosts
Views
Activity
Aug ’25
Reply to Question about Xcode
Here is the structure of a project with a Watch companion app (it was created several years ago, with Xcode 9 or 10 probably and uses WatchKit and not SwiftUI): I have highlighted the 3 info.plist the first is the usual for iOS app, in iOS section (bundle display name is 'MyApp') Second in myApp Watch (bundle display name is 'MyApp'). The content is: third info.plist in myApp Watch Extension (bundle display name is 'MyApp Watch extension'). Its content is: Note also infoPlist, which contains some localizations, with keys as CFBundleName, NSCameraUsageDescription I don't remember how they were created (I think it was automatic when creating watch companion, but you can probably recreate manually). Hope that helps.
Replies
Boosts
Views
Activity
Aug ’25
Reply to Restricting App Installation to Devices Supporting Apple Intelligence Without Triggering Game Mode
Effectively, exploring what could be done with UIRequiredDeviceCapabilities in Info.plist appears the best option. https://stackoverflow.com/questions/10191657/restrict-to-certain-ios-target-devices-for-app-store-submission May be you can find a listed capability that matches approximately with support of Apple Intelligence. But unfortunately, gaming seems to be the only one to discriminate for A17 chip. https://developer.apple.com/support/required-device-capabilities/
Replies
Boosts
Views
Activity
Aug ’25
Reply to Juicy Defend - Fruit vs Robot app "waiting for review" for +6 days
Welcome to the forum. Until you receive a request from reviewer, there is nothing to do. What type of app is it ? Does it include in app purchase ? Is it a paying app ? You should also note that this forum is not an official channel to Apple, even though some Apple's engineer contribute to it. So you'd better contact support.
Replies
Boosts
Views
Activity
Aug ’25
Reply to why no "fold all" option?
My understanding is it is because folding is multi level. Unfold is easy: everything that was folded, whatever level, will unfold. But folding all: what you you keep ? Just very top level, at class level, where you see nothing more ? At the first level func ? So you should have to specify the level to make it any use. So, imagine what should be the result of a fold all and you may find it is impracticable.
Replies
Boosts
Views
Activity
Aug ’25
Reply to @State variable returns empty despite being set in .onAppear function
Finally, to give you in depth explanation about the use of @State in DataView: https://forums.swift.org/t/im-so-confused-why-state-var-inside-a-view-do-not-change-when-you-call-a-method-on-this-view-from-some-outer-view/31944/7 And you can test with a Binding: struct DataView2: View { @Binding var datum: Data2 var body: some View { Text("DataView \(datum.str)") } } calling it with DataView2(datum: $data[index]) Good continuation.
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Aug ’25
Reply to @State variable returns empty despite being set in .onAppear function
Finally, to give you in depth explanation about the use of @State in DataView: https://forums.swift.org/t/im-so-confused-why-state-var-inside-a-view-do-not-change-when-you-call-a-method-on-this-view-from-some-outer-view/31944/7 And you can test with a Binding: struct DataView2: View { @Binding var datum: Data2 var body: some View { Text("DataView \(datum.str)") } } calling it with DataView2(datum: $data[index]) Good continuation.
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Aug ’25
Reply to @State variable returns empty despite being set in .onAppear function
That's the error I told you in a previous post. @State var datum: Data Replace with var datum: Data If tha works, don't forget to close the thread by marking this answer as correct. Otherwise, explain.
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Aug ’25
Reply to @State variable returns empty despite being set in .onAppear function
This cannot compile. data is a constant that you try to modify. let data = try Data(contentsOf: url) let jsonDecoded = try JSONDecoder().decode([Data2].self, from: data) data = jsonDecoded The code I sent was: let dataRead = try Data(contentsOf: url) let jsonDecoded = try JSONDecoder().decode([Data2].self, from: dataRead) data = jsonDecoded With these changes, your code works OK. Could you show the DataView code ?
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Aug ’25
Reply to @State variable returns empty despite being set in .onAppear function
Why is it data and not datum on line 28 of the first code ? DataView(data: data[index]) With this simple change, it works here. DataView(datum: data[index]) The screenshots show the change in String x
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Aug ’25
Reply to @State variable returns empty despite being set in .onAppear function
Did you change datum to a simple var and not a State var ? Could you show the complete code, to see how Binding is used. Logically, @Binding var index: Int should be in the ContentView and the @State var index = 0 in the other view But I would need to check. PS: don't forget to close the thread, eventually starting a new one where you reference this one.
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Aug ’25
Reply to @State variable returns empty despite being set in .onAppear function
Another point. In DataView, index should not be a State variable. Add a button in ContentView VStack { if showView && (index >= 0) && (index < data.count) { DataView(datum: data[index]) } Spacer() HStack { Text("Index: \(index) -> ") Button("Next") { index += 1 if index >= data.count { index = 0 } } } } You will see that text in DataView does not change Text("DataView \(datum.str)") always says DataView String 1 Now change DataView as follows to get it updated on index change by button press: struct DataView: View { /*@State*/ var datum: Data2 var body: some View { Text("DataView \(datum.str)") } } Note: I renamed data to datum for an array item, to differentiate from the array. Now, I have to update my initial answer. In fact, no need for showView and Dispatch (even though that made it work). Just test index: if (index < data.count) { DataView(datum: data[index]) Without the index test, it crashes… Swift/ContiguousArrayBuffer.swift:691: Fatal error: Index out of range Reason is that DataView is not called immediately but only when State var data is populated by getData (then count changes) and has all its elements. So the test has a similar effect as Dispatch to wait for data to be fetched.
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Aug ’25
Reply to @State variable returns empty despite being set in .onAppear function
It is a question of timing. When onAppear returns, and DataView is called, the array is not yet populated, even though its count is already OK. You have to wait for a short time in onAppear (0.01 s should be OK). Here is the solution. I had to rename Data to avoid the error above (Data is a Foundation type). I renamed to Data2 struct Data2: Decodable, Hashable { let index: Int let str: String } struct DataView: View { @State var data: Data2 var body: some View { Text("DataView \(data.str)") } } struct ContentView: View { @State var showView = false // To wait for array to be populated before we display the view @State var data: [Data2] @State var index: Int = 0 var body: some View { VStack { if showView { DataView(data: data[index]) // Text("Hello \(data.count)") // To test if needed ; without async, data.count is 2. Seems OK, but… // Text("Hello \(data.count) index \(index) \(data[0].str)") // but without async, it will crash, as data is not populated yet, even if count is already 2 } } .onAppear { let filePath = Bundle.main.path(forResource: "data", ofType: "json") let url = URL(fileURLWithPath: filePath!) data = getData(url: url) DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { // <<-- THE KEY POINT 0.1 sec delay self.showView = true } } } func getData(url: URL) -> [Data2] { do { let data = try Data(contentsOf: url) let jsonDecoded = try JSONDecoder().decode([Data2].self, from: data) return jsonDecoded } catch let error as NSError { print("Fail: \(error.localizedDescription)") } catch { print("Fail: \(error)") } return [] } } Credit: https://stackoverflow.com/questions/62355428/how-do-i-show-a-new-view-after-some-delay-amount-of-time-swiftui A simpler option is to use an init: struct ContentView: View { @State var data: [Data2] @State var index: Int = 0 init() { let filePath = Bundle.main.path(forResource: "data", ofType: "json") let url = URL(fileURLWithPath: filePath!) // data = getData(url: url) // We cannot call getData in init do { let dataRead = try Data(contentsOf: url) let jsonDecoded = try JSONDecoder().decode([Data2].self, from: dataRead) data = jsonDecoded return } catch let error as NSError { print("Fail: \(error.localizedDescription)") } catch { print("Fail: \(error)") } data = [] return } var body: some View { VStack { DataView(data: data[index]) } } }
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Aug ’25