Post

Replies

Boosts

Views

Activity

Reply to Editable hierarchical list in runtime
When you add on child line, what do you add ? A child of the parent ? A child of the child ?   I need to have both for each line item. So simple! Remove some tests. Here is an updated code… struct ContentView: View { @State var data: [FileItem] = [ FileItem(name: "First", children: [FileItem(name: "childF1"), FileItem(name: "childF2")]), FileItem(name: "Second", children: [FileItem(name: "childS1"), FileItem(name: "childS2"), FileItem(name: "childS3")]), FileItem(name: "Third", children: [FileItem(name: "childT1"), FileItem(name: "childT2")]), ] @FocusState private var focusedField: String? var body: some View { List($data, children: \.children) { $item in HStack { TextField("", text: $item.name) .focused($focusedField, equals: item.name) // avoid keyboard to disappear at each character .task { self.focusedField = item.name } // Text(item.name) // If there are no children, we cannot remove it if item.children != nil { // So it is parent, maybe with no child [] Spacer() Button("Add child") { // let's search its position in data print("added") for (index, parent) in data.enumerated() { if parent.name == item.name && parent.children != nil { // double check on nil data[index].children!.append(FileItem(name: "new child")) } } } .buttonStyle(.borderless) } // if item.children == nil || item.children!.isEmpty { // nil when item is child, empty for parent Spacer() Button("Remove") { // This is a simple implementation if only children, no grandChildren // if grandchildren, need to have a recursive search for the parent var deleteDone = false for (index, individual) in data.enumerated() { // remove child if !deleteDone { if individual.children != nil && !individual.children!.isEmpty { for child in individual.children! { if child.name == item.name { var newChildren = individual.children! newChildren.removeAll(where: { $0.name == item.name }) data[index].children = newChildren deleteDone = true break } } } } // REMOVE THIS -> else { // remove parent if !deleteDone { for (index, individual) in data.enumerated() { if individual.name == item.name { data.remove(at: index) deleteDone = true break } } } // } } } .buttonStyle(.borderless) // } } } } } There are still some tuning to be done (error when removing an added child). But that should give you a start point. As I explained, if you want more levels, you can use the same struct and List. But you will have to write the function to search for an item in the hierarchy in order to add or remove it in the data. That's a good exercise.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’24
Reply to Editable hierarchical list in runtime
Removing parent needs an additional test: } else { // It is the parent for (index, parent) in data.enumerated() { if parent.name == item.name { data.remove(at: index) print("remove \(item.name)") } } For completeness, a very basic Add child. I have assumed that children in nil for a child and not nil but may be empty for parent.: struct FileItem: Identifiable { let name: String var children: [FileItem]? // 👈🏻 Will be nil if child at lowest level of hierarchy ; otherwise for parent, should be [] when no child var id: String { name } } struct ContentView: View { @State var data: [FileItem] = [ FileItem(name: "First", children: [FileItem(name: "childF1"), FileItem(name: "childF2")]), FileItem(name: "Second", children: [FileItem(name: "childS1"), FileItem(name: "childS2"), FileItem(name: "childS3")]), FileItem(name: "Third", children: [FileItem(name: "childT1"), FileItem(name: "childT2")]), ] // var body: some View { // List(data, children: \.children, rowContent: { Text($0.name) }) // } var body: some View { List(data, children: \.children) { item in HStack { Text(item.name) // If there are no children, we cannot remove it if item.children != nil { // So it is parent, maybe with no child [] Spacer() Button("Add child") { // let's search its position in data for (index, parent) in data.enumerated() { if parent.name == item.name && parent.children != nil { // double check on nil data[index].children!.append(FileItem(name: "new child")) } } } } if item.children == nil || item.children!.isEmpty { // nil when item is child, empty for parent Spacer() Button("Remove") { // This is a simple implementation if only children, no grandChildren // if grandchildren, need to have a recursive search for the parent for (index, parent) in data.enumerated() { // If it is children if parent.children != nil && !parent.children!.isEmpty { for child in parent.children! { if child.name == item.name { var newChildren = parent.children! newChildren.removeAll(where: { $0.name == item.name }) data[index].children = newChildren print("remove \(item.name)") } } } else { // It is the parent for (index, parent) in data.enumerated() { if parent.name == item.name { data.remove(at: index) print("remove \(item.name)") } } } } } } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’24
Reply to Editable hierarchical list in runtime
Here is a very simple example, just to show how to use hierarchical List struct FileItem: Identifiable { let name: String var children: [FileItem]? var id: String { name } } struct ContentView: View { @State var data: [FileItem] = [FileItem(name: "First", children: [FileItem(name: "child1"), FileItem(name: "child2")])] // State, so that you can modify var body: some View { List(data, children: \.children, rowContent: { Text($0.name) }) } }   In Xcode documentation (searching for List), you will find more details on how to use hierarchical lists: Creating hierarchical lists You can also create a hierarchical list of arbitrary depth by providing tree-structured data and a children parameter that provides a key path to get the child nodes at any level. The following example uses a deeply-nested collection of a custom FileItem type to simulate the contents of a file system. The list created from this data uses collapsing cells to allow the user to navigate the tree structure. struct ContentView: View { struct FileItem: Hashable, Identifiable, CustomStringConvertible { var id: Self { self } var name: String var children: [FileItem]? = nil var description: String { switch children { case nil: return "📄 \(name)" case .some(let children): return children.isEmpty ? "📂 \(name)" : "📁 \(name)" } } } let fileHierarchyData: [FileItem] = [ FileItem(name: "users", children: [FileItem(name: "user1234", children: [FileItem(name: "Photos", children: [FileItem(name: "photo001.jpg"), FileItem(name: "photo002.jpg")]), FileItem(name: "Movies", children: [FileItem(name: "movie001.mp4")]), FileItem(name: "Documents", children: []) ]), FileItem(name: "newuser", children: [FileItem(name: "Documents", children: []) ]) ]), FileItem(name: "private", children: nil) ] var body: some View { List(fileHierarchyData, children: \.children) { item in Text(item.description) } } }    Here is a simple remove implementation: struct ContentView: View { @State var data: [FileItem] = [FileItem(name: "First", children: [FileItem(name: "child1"), FileItem(name: "child2")])] var body: some View { List(data, children: \.children) { item in HStack { Text(item.name) // If there are children, we cannot remove it if item.children == nil || item.children!.isEmpty { Spacer() Button("Remove"){ // This is a simple implementation if only children, no grandChildren // if grandchildren, need to have a recursive search for the parent for (index, parent) in data.enumerated() { // If it is children if parent.children != nil && !parent.children!.isEmpty { for child in parent.children! { if child.name == item.name { var newChildren = parent.children! newChildren.removeAll(where: { $0.name == item.name }) data[index].children = newChildren print("remove \(item.name)") } } } else { // It is the parent for (index, parent) in data.enumerated() { data.remove(at: index) print("remove \(item.name)") } } } } } } } } } Don't forget to close the thread if that's OK. Otherwise, explain where the problem is.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’24
Reply to User Data is getting randomly deleted
Could there be a link with the bug solved in Xcode 15.4 according to release notes:   Resolved Issues Fixed: In certain circumstances, an app can’t read the contents of its own data container after replacing the content of the data container using Xcode or devicectl. (116698465) (FB13253099)
Topic: App & System Services SubTopic: General Tags:
May ’24
Reply to app rejected
You're supposed to provide requested information. Try to imagine reviewer concern: they see a developer speak in the name a company without any official credential. It could well be someone usurping the name of the company to publish an app without their consent. Reviewer cannot guess you have a (verbal) agreement. If the owner is a friend of yours, that should be pretty easy to get the signed document.
May ’24
Reply to SwiftData relationships
In the “Vegetable” class, why is the field “notes” an array of type Notes? You may have several notes, so it is logical to get them in an array. What else did you think about ?   Again in the “Vegetable” class does the field “notes” get stored in the database, if so what is stored? By default, all non-computed attributes are stored. Unless you use the @Transient macro.   In the “Note” Class it looks like the whole of the class “Vegetable” gets stored in the variable “vegetable”, which may or may not get stored in the database. With @Relationship, SwiftData knows what needs to be saved to be able to rebuild the relations when needed. This tutorial should give you some insight.
Topic: App & System Services SubTopic: iCloud Tags:
May ’24
Reply to Swift UI How can I get the click of a button to change the wording of Label
my label should be a state var. And you cannot change with string value, but just reassign a new label: struct ContentView: View { @State private var myLabel = Label("Text to be Changed", systemImage: "circle") var body: some View { Spacer() Button("Change Label Wording"){ myLabel = Label("Changed text", systemImage: "star") } Spacer() myLabel Spacer() } } You could also do it differently. Create a state variable @State private var newLabel = false Toggle in button action: Button("Change Label Wording"){ newLabel.toggle() } Here is a small code snippet to show: struct ContentView: View { @State private var newLabel = false var body: some View { Spacer() Button("Change Label Wording"){ newLabel.toggle() // myLabel.stringValue = "Changed text" } Spacer() Text(newLabel ? "Changed text" : "Text to be Changed") // Or this form Spacer() if newLabel { Text("Changed text (2)") } else { Text("Text to be Changed (2)") } Spacer() } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’24
Reply to FCPXML Creation issue...
Is that just a warning ? Does the file works correctly ? There are many references to similar issues on the web (notably on discussions.apple.com). Did you search ? For instance, this one, where error was due to timecode: https://discussions.apple.com/thread/255188736?sortBy=best
Topic: Media Technologies SubTopic: Video Tags:
May ’24
Reply to Error event - Minimed Mobile App . Triggered by insufficient update interval of the Watch iOS system of only 50 updates/day problem with update interval of the Apple Watch iOS
Welcome to the forum. You have a problem with an existing app ? So this forum is not the right one. you should contact the developer directly. this forum is to be uses for your app, if you have any issue during developpent . So you‘d better close this thread and post it again on minimed forum or send directly to its developer.
May ’24
Reply to Editable hierarchical list in runtime
When you add on child line, what do you add ? A child of the parent ? A child of the child ?   I need to have both for each line item. So simple! Remove some tests. Here is an updated code… struct ContentView: View { @State var data: [FileItem] = [ FileItem(name: "First", children: [FileItem(name: "childF1"), FileItem(name: "childF2")]), FileItem(name: "Second", children: [FileItem(name: "childS1"), FileItem(name: "childS2"), FileItem(name: "childS3")]), FileItem(name: "Third", children: [FileItem(name: "childT1"), FileItem(name: "childT2")]), ] @FocusState private var focusedField: String? var body: some View { List($data, children: \.children) { $item in HStack { TextField("", text: $item.name) .focused($focusedField, equals: item.name) // avoid keyboard to disappear at each character .task { self.focusedField = item.name } // Text(item.name) // If there are no children, we cannot remove it if item.children != nil { // So it is parent, maybe with no child [] Spacer() Button("Add child") { // let's search its position in data print("added") for (index, parent) in data.enumerated() { if parent.name == item.name && parent.children != nil { // double check on nil data[index].children!.append(FileItem(name: "new child")) } } } .buttonStyle(.borderless) } // if item.children == nil || item.children!.isEmpty { // nil when item is child, empty for parent Spacer() Button("Remove") { // This is a simple implementation if only children, no grandChildren // if grandchildren, need to have a recursive search for the parent var deleteDone = false for (index, individual) in data.enumerated() { // remove child if !deleteDone { if individual.children != nil && !individual.children!.isEmpty { for child in individual.children! { if child.name == item.name { var newChildren = individual.children! newChildren.removeAll(where: { $0.name == item.name }) data[index].children = newChildren deleteDone = true break } } } } // REMOVE THIS -> else { // remove parent if !deleteDone { for (index, individual) in data.enumerated() { if individual.name == item.name { data.remove(at: index) deleteDone = true break } } } // } } } .buttonStyle(.borderless) // } } } } } There are still some tuning to be done (error when removing an added child). But that should give you a start point. As I explained, if you want more levels, you can use the same struct and List. But you will have to write the function to search for an item in the hierarchy in order to add or remove it in the data. That's a good exercise.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to List or a ForEach from a binding: keyboard issue
Did you get any answer to your FB ? I may have found with focusField Declare @FocusState private var focusedField: String? Then in TextField TextField("", text: $msg) .focused($focusedField, equals: msg) .task { self.focusedField = msg }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to Editable hierarchical list in runtime
Removing parent needs an additional test: } else { // It is the parent for (index, parent) in data.enumerated() { if parent.name == item.name { data.remove(at: index) print("remove \(item.name)") } } For completeness, a very basic Add child. I have assumed that children in nil for a child and not nil but may be empty for parent.: struct FileItem: Identifiable { let name: String var children: [FileItem]? // 👈🏻 Will be nil if child at lowest level of hierarchy ; otherwise for parent, should be [] when no child var id: String { name } } struct ContentView: View { @State var data: [FileItem] = [ FileItem(name: "First", children: [FileItem(name: "childF1"), FileItem(name: "childF2")]), FileItem(name: "Second", children: [FileItem(name: "childS1"), FileItem(name: "childS2"), FileItem(name: "childS3")]), FileItem(name: "Third", children: [FileItem(name: "childT1"), FileItem(name: "childT2")]), ] // var body: some View { // List(data, children: \.children, rowContent: { Text($0.name) }) // } var body: some View { List(data, children: \.children) { item in HStack { Text(item.name) // If there are no children, we cannot remove it if item.children != nil { // So it is parent, maybe with no child [] Spacer() Button("Add child") { // let's search its position in data for (index, parent) in data.enumerated() { if parent.name == item.name && parent.children != nil { // double check on nil data[index].children!.append(FileItem(name: "new child")) } } } } if item.children == nil || item.children!.isEmpty { // nil when item is child, empty for parent Spacer() Button("Remove") { // This is a simple implementation if only children, no grandChildren // if grandchildren, need to have a recursive search for the parent for (index, parent) in data.enumerated() { // If it is children if parent.children != nil && !parent.children!.isEmpty { for child in parent.children! { if child.name == item.name { var newChildren = parent.children! newChildren.removeAll(where: { $0.name == item.name }) data[index].children = newChildren print("remove \(item.name)") } } } else { // It is the parent for (index, parent) in data.enumerated() { if parent.name == item.name { data.remove(at: index) print("remove \(item.name)") } } } } } } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to Editable hierarchical list in runtime
Here is a very simple example, just to show how to use hierarchical List struct FileItem: Identifiable { let name: String var children: [FileItem]? var id: String { name } } struct ContentView: View { @State var data: [FileItem] = [FileItem(name: "First", children: [FileItem(name: "child1"), FileItem(name: "child2")])] // State, so that you can modify var body: some View { List(data, children: \.children, rowContent: { Text($0.name) }) } }   In Xcode documentation (searching for List), you will find more details on how to use hierarchical lists: Creating hierarchical lists You can also create a hierarchical list of arbitrary depth by providing tree-structured data and a children parameter that provides a key path to get the child nodes at any level. The following example uses a deeply-nested collection of a custom FileItem type to simulate the contents of a file system. The list created from this data uses collapsing cells to allow the user to navigate the tree structure. struct ContentView: View { struct FileItem: Hashable, Identifiable, CustomStringConvertible { var id: Self { self } var name: String var children: [FileItem]? = nil var description: String { switch children { case nil: return "📄 \(name)" case .some(let children): return children.isEmpty ? "📂 \(name)" : "📁 \(name)" } } } let fileHierarchyData: [FileItem] = [ FileItem(name: "users", children: [FileItem(name: "user1234", children: [FileItem(name: "Photos", children: [FileItem(name: "photo001.jpg"), FileItem(name: "photo002.jpg")]), FileItem(name: "Movies", children: [FileItem(name: "movie001.mp4")]), FileItem(name: "Documents", children: []) ]), FileItem(name: "newuser", children: [FileItem(name: "Documents", children: []) ]) ]), FileItem(name: "private", children: nil) ] var body: some View { List(fileHierarchyData, children: \.children) { item in Text(item.description) } } }    Here is a simple remove implementation: struct ContentView: View { @State var data: [FileItem] = [FileItem(name: "First", children: [FileItem(name: "child1"), FileItem(name: "child2")])] var body: some View { List(data, children: \.children) { item in HStack { Text(item.name) // If there are children, we cannot remove it if item.children == nil || item.children!.isEmpty { Spacer() Button("Remove"){ // This is a simple implementation if only children, no grandChildren // if grandchildren, need to have a recursive search for the parent for (index, parent) in data.enumerated() { // If it is children if parent.children != nil && !parent.children!.isEmpty { for child in parent.children! { if child.name == item.name { var newChildren = parent.children! newChildren.removeAll(where: { $0.name == item.name }) data[index].children = newChildren print("remove \(item.name)") } } } else { // It is the parent for (index, parent) in data.enumerated() { data.remove(at: index) print("remove \(item.name)") } } } } } } } } } Don't forget to close the thread if that's OK. Otherwise, explain where the problem is.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to Can somebody explain why i get this error ? all photos are uploaded. This is a very well know issue
Sometimes upload fails. You have to reload again the specific image. yYou do not show the screenshots section, that would be useful.
Replies
Boosts
Views
Activity
May ’24
Reply to My SwiftUI code is becoming un-SwiftUI-y. I'm looking to make things right again.
If I understand correctly, you could use .onChange modifier to update the content each time user updates one of the settings. If you want more precise answer, please show the part of code where user updates settings.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to User Data is getting randomly deleted
Could there be a link with the bug solved in Xcode 15.4 according to release notes:   Resolved Issues Fixed: In certain circumstances, an app can’t read the contents of its own data container after replacing the content of the data container using Xcode or devicectl. (116698465) (FB13253099)
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to How to prevent Menu view from redrawing?
What does the backend modifies ? Does it modify PresetPicker ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to app rejected
You're supposed to provide requested information. Try to imagine reviewer concern: they see a developer speak in the name a company without any official credential. It could well be someone usurping the name of the company to publish an app without their consent. Reviewer cannot guess you have a (verbal) agreement. If the owner is a friend of yours, that should be pretty easy to get the signed document.
Replies
Boosts
Views
Activity
May ’24
Reply to SwiftData relationships
In the “Vegetable” class, why is the field “notes” an array of type Notes? You may have several notes, so it is logical to get them in an array. What else did you think about ?   Again in the “Vegetable” class does the field “notes” get stored in the database, if so what is stored? By default, all non-computed attributes are stored. Unless you use the @Transient macro.   In the “Note” Class it looks like the whole of the class “Vegetable” gets stored in the variable “vegetable”, which may or may not get stored in the database. With @Relationship, SwiftData knows what needs to be saved to be able to rebuild the relations when needed. This tutorial should give you some insight.
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to Submission rejected has mention App Review Guideline 3.1.5(iii)
We just provide decentralized application for users to easily interact with our smart contracts. That's not very clear. What does your app really offers ? Are a you aka go between with exchange organisations ? In any case, I would advise you to very clearly explain as a comment to reviewer, what your app does.
Replies
Boosts
Views
Activity
May ’24
Reply to Apple Developer Reject Because of Report Criminal Activity
My App detects the user's location to provide a list of nearby police, ambulances, etc to use for emergency purposes. AFAIU, that does not change appStore review requirement. As you provide users with police contacts, you have to have an agreement with local authority.
Replies
Boosts
Views
Activity
May ’24
Reply to Swift UI How can I get the click of a button to change the wording of Label
my label should be a state var. And you cannot change with string value, but just reassign a new label: struct ContentView: View { @State private var myLabel = Label("Text to be Changed", systemImage: "circle") var body: some View { Spacer() Button("Change Label Wording"){ myLabel = Label("Changed text", systemImage: "star") } Spacer() myLabel Spacer() } } You could also do it differently. Create a state variable @State private var newLabel = false Toggle in button action: Button("Change Label Wording"){ newLabel.toggle() } Here is a small code snippet to show: struct ContentView: View { @State private var newLabel = false var body: some View { Spacer() Button("Change Label Wording"){ newLabel.toggle() // myLabel.stringValue = "Changed text" } Spacer() Text(newLabel ? "Changed text" : "Text to be Changed") // Or this form Spacer() if newLabel { Text("Changed text (2)") } else { Text("Text to be Changed (2)") } Spacer() } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to FCPXML Creation issue...
Is that just a warning ? Does the file works correctly ? There are many references to similar issues on the web (notably on discussions.apple.com). Did you search ? For instance, this one, where error was due to timecode: https://discussions.apple.com/thread/255188736?sortBy=best
Topic: Media Technologies SubTopic: Video Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to Error event - Minimed Mobile App . Triggered by insufficient update interval of the Watch iOS system of only 50 updates/day problem with update interval of the Apple Watch iOS
Welcome to the forum. You have a problem with an existing app ? So this forum is not the right one. you should contact the developer directly. this forum is to be uses for your app, if you have any issue during developpent . So you‘d better close this thread and post it again on minimed forum or send directly to its developer.
Replies
Boosts
Views
Activity
May ’24