Post

Replies

Boosts

Views

Activity

Reply to HELP ME!!
I do not declare a new State var but an AppStorage… Maybe the State var is to know you have saved and then disable Save Button. Declare this: @AppStorage("Names") var storedNames: String = "" Then, in the Save, we concatenate all the names. Note: AppStorage saves in UserDefaults. But it cannot save directly and array, so we transform the array of String into a String, by concatenation. In Load, we de concatenate. You will see how fun on arrays, as reduce, split and map are really powerful here. If you don't know them, learn by reading documentation. It is really important to understand how they work So the complete code: struct ContentView: View { @State private var names: [String] = [] @State private var nameToAdd = "" @State private var pickedName = "" @State private var shouldRemovePickedName = false @AppStorage("Names") var storedNames: String = "" // The concatenation of all the names, separated by commas var body: some View { VStack { VStack(spacing: 8) { Image(systemName: "person.3.sequence.fill") .foregroundStyle(.tint) .symbolRenderingMode(.hierarchical) Text("Pick-a-Pal") } .font(.title) .bold() //3項条件演算子 Text(pickedName.isEmpty ? "" : pickedName) .font(.title2) .bold() .foregroundStyle(.tint) List { ForEach(names, id: \.self) { name in Text(name) } } .clipShape(RoundedRectangle(cornerRadius: 8)) TextField("Add Name", text: $nameToAdd) //単語の自動修正をオフにする .autocorrectionDisabled() .onSubmit { if !nameToAdd.isEmpty { if names.contains(nameToAdd) { // You could add an alert, or sound a beep if already exists } else { names.append(nameToAdd) } nameToAdd = "" } } Divider() Toggle("Remove when picked", isOn: $shouldRemovePickedName) Button { if let randomName = names.randomElement() { pickedName = randomName if shouldRemovePickedName { names.removeAll() { name in return (name == randomName) } } } else { pickedName = "" } } label: { Text("Pick Random Name") .padding(.vertical, 8) .padding(.horizontal, 16) } .buttonStyle(.borderedProminent) .font(.title2) Divider() HStack { // Show 2 buttons on HStack Button { // We concatenate the names ; reduce func is useful for this storedNames = names.reduce("", { $0 + $1 + "," }) // Comma to separate next name // A more readable equivalent is: // storedNames = names.reduce("", { concatenate, name in concatenate + name + "," }) print(storedNames) } label: { Text("Save Names") } Spacer(minLength: 40) Button { // We need to de-concatenate: split function splits the elements in a string into an array, dividing by the separator names = storedNames.split(separator: ",").map( { String($0) }) // as split returns an array of subtrings, we need to map into String print(names) // To see what we get } label: { Text("Load saved Names") } } } .padding() } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’24
Reply to Guideline 5.1.2 : The primary purpose of the app is still to encourage users to perform digital tasks in exchange for compensation, watch ads and/or perform other marketing-oriented tasks, which is not appropriate.
there are other apps out there that have a similar business model That's not argument reviewers will ever consider. May be they have missed it for those other apps (as hinted in the answer), but that does not entitle others to do the same. According to your post, your app does violate guideline 5.1.2 and, now that it has been noticed, it's very likely it will be rejected until you change your app.   Could they have objected because I included conversion of proprietary currency to $ ? What do you mean by "proprietary" ?
May ’24
Reply to HELP ME!!
Problem:I can't implement this program which this below text say. How do I write the code?? What do you mean ? You cannot enter code or you don't know how to code ? Which part ? onSubmit ? Here is how to do it for onSubmit .onSubmit { if !nameToAdd.isEmpty { if names.contains(nameToAdd) { // You could add an alert, or sound a beep if already exists } else { names.append(nameToAdd) } nameToAdd = "" } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’24
Reply to Bug: If you have ever made a TestFlight build with a higher version number, you won't get any crash nor feedback reports from users for lower versions!
I understand the mistake was a long time ago (build 55). IMHO, it is not a bug but an intended policy of AppStore to make sure users are not confused by release versions that go up and down. So little chance a bug report would lead to any change. Which means we effectively have to double check all the meta information before pushing on the Appstore. Can't you make your new version 2.0.1 with build 211 ? I understand it is not the best, but that's the only option I know. Last hope: contact developers' support to see if they can do anything for you ?
May ’24
Reply to "Unexpectedly found nil while unwrapping an Optional value" in URL
If I understand, the error is here: func fetchLink() async { do { url = URL(string: GlobalString().link) let (data, _) = try await URLSession.shared.data(from: url!) If you look at URL documentation, you see that URL(string: _) returns an optional which may be nil (that's what happens in your case) init?(string: String) Creates a URL instance from the provided string. Why is it nil, that's what you have now to investigate. To make your code robust, test for nil: func fetchLink() async { do { url = URL(string: GlobalString().link) if url == nil { print(GlobalString()) // <<-- To understand what happens return // do not continue } let (data, _) = try await URLSession.shared.data(from: url!) // <<-- cannot be nil anymore Do the same by testing post_url if the error is here: let postUrl: URL? = linkResponse.post_url != nil ? URL(string: linkResponse.post_url!) : nil Note: In Swift we avoid using underscore and use camelCase instead. That means post_url should better be postUrl or postURL for instance.
Topic: Programming Languages SubTopic: Swift Tags:
May ’24
Reply to Swiftui - Pressing button in a list also actions another button
You have to set buttonStyle (does not work with default value), such as: .buttonStyle(.borderless) // Or some other style So your code: List(am.students) { item in HStack { Text(item.name).font(fancyFont) Spacer() Button(item.casual ? "All Paid" : "Reverse All Paid") { // Issue: pressing this button also results in Remove button action being invoked. item.casual = !item.casual } .buttonStyle(.borderless) // <<-- ADD THIS Or some other style .foregroundColor(Color(white: 0.15)) .padding(3) .overlay( RoundedRectangle(cornerRadius: 5) .stroke(Color(white: 0.5), lineWidth: 3) ) Spacer().frame(width: 40) Button("Remove") { Task { await am.delete(student: item) } } .buttonStyle(.borderless) // <<-- ADD THIS Or some other style .foregroundColor(Color(white: 0.15)) .frame(width: 80) .padding(3) .overlay( RoundedRectangle(cornerRadius: 5) .stroke(Color(white: 0.5), lineWidth: 3) ) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’24
Reply to How might I get didSet behaviour on an AppStorage var?
Surprising. I tested the code proposed here and it works: https://stackoverflow.com/questions/63171806/willset-not-being-called-on-swiftuis-new-appstorage-property struct DemoAppStorageDidSet: View { @AppStorage("codeResult") var codeResult: String = "Default" { // << default value willSet { print("willSet: \(newValue)") } didSet { print("didSet: \(oldValue)") } } var body: some View { VStack { Text("Code Result: \(codeResult)") Divider() Button("AppStore Update") { self.codeResult = "AppStore" // << activates willSet/didSet !! } Divider() Button("UserDefaults Update") { UserDefaults.standard.set("UserDefaults", forKey: "codeResult") } } } }   Tapping "AppStore Update" logs as expected: willSet: AppStore didSet: Default Tapping a second time: willSet: AppStore didSet: AppStore So please show your complete code that does not work (maybe stupid question: are you sure the console is visible for log ?)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’24
Reply to FORM PROBLEMS
That's a limit of SwiftUI: a view cannot have more than 10 subviews (here sections). There is a workaround: group up to 10 sections in a Group Form { Group { Section { } Section { } // up to 10 sections } Group { Section { } Section { } // up to 10 sections } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’24
Reply to SF Symbol
Where did you see this symbol ? In an Apple's app or another app ? I searched also for circle and for dotted. Could not find it either. moon.circle is relatively close to this. But not the same.
Topic: Design SubTopic: General Tags:
May ’24
Reply to HELP ME!!
I do not declare a new State var but an AppStorage… Maybe the State var is to know you have saved and then disable Save Button. Declare this: @AppStorage("Names") var storedNames: String = "" Then, in the Save, we concatenate all the names. Note: AppStorage saves in UserDefaults. But it cannot save directly and array, so we transform the array of String into a String, by concatenation. In Load, we de concatenate. You will see how fun on arrays, as reduce, split and map are really powerful here. If you don't know them, learn by reading documentation. It is really important to understand how they work So the complete code: struct ContentView: View { @State private var names: [String] = [] @State private var nameToAdd = "" @State private var pickedName = "" @State private var shouldRemovePickedName = false @AppStorage("Names") var storedNames: String = "" // The concatenation of all the names, separated by commas var body: some View { VStack { VStack(spacing: 8) { Image(systemName: "person.3.sequence.fill") .foregroundStyle(.tint) .symbolRenderingMode(.hierarchical) Text("Pick-a-Pal") } .font(.title) .bold() //3項条件演算子 Text(pickedName.isEmpty ? "" : pickedName) .font(.title2) .bold() .foregroundStyle(.tint) List { ForEach(names, id: \.self) { name in Text(name) } } .clipShape(RoundedRectangle(cornerRadius: 8)) TextField("Add Name", text: $nameToAdd) //単語の自動修正をオフにする .autocorrectionDisabled() .onSubmit { if !nameToAdd.isEmpty { if names.contains(nameToAdd) { // You could add an alert, or sound a beep if already exists } else { names.append(nameToAdd) } nameToAdd = "" } } Divider() Toggle("Remove when picked", isOn: $shouldRemovePickedName) Button { if let randomName = names.randomElement() { pickedName = randomName if shouldRemovePickedName { names.removeAll() { name in return (name == randomName) } } } else { pickedName = "" } } label: { Text("Pick Random Name") .padding(.vertical, 8) .padding(.horizontal, 16) } .buttonStyle(.borderedProminent) .font(.title2) Divider() HStack { // Show 2 buttons on HStack Button { // We concatenate the names ; reduce func is useful for this storedNames = names.reduce("", { $0 + $1 + "," }) // Comma to separate next name // A more readable equivalent is: // storedNames = names.reduce("", { concatenate, name in concatenate + name + "," }) print(storedNames) } label: { Text("Save Names") } Spacer(minLength: 40) Button { // We need to de-concatenate: split function splits the elements in a string into an array, dividing by the separator names = storedNames.split(separator: ",").map( { String($0) }) // as split returns an array of subtrings, we need to map into String print(names) // To see what we get } label: { Text("Load saved Names") } } } .padding() } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to How know if windowWillClose: is invoked by X button click
Did you try changing the action of the close button ? And set a global variable closedByUser to true https://stackoverflow.com/questions/7237445/override-nswindow-close-button Then you can use closedByUser in windoWillClose to do what you want (and reset closedByUser to false)
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to Guideline 5.1.2 : The primary purpose of the app is still to encourage users to perform digital tasks in exchange for compensation, watch ads and/or perform other marketing-oriented tasks, which is not appropriate.
there are other apps out there that have a similar business model That's not argument reviewers will ever consider. May be they have missed it for those other apps (as hinted in the answer), but that does not entitle others to do the same. According to your post, your app does violate guideline 5.1.2 and, now that it has been noticed, it's very likely it will be rejected until you change your app.   Could they have objected because I included conversion of proprietary currency to $ ? What do you mean by "proprietary" ?
Replies
Boosts
Views
Activity
May ’24
Reply to HELP ME!!
Problem:I can't implement this program which this below text say. How do I write the code?? What do you mean ? You cannot enter code or you don't know how to code ? Which part ? onSubmit ? Here is how to do it for onSubmit .onSubmit { if !nameToAdd.isEmpty { if names.contains(nameToAdd) { // You could add an alert, or sound a beep if already exists } else { names.append(nameToAdd) } nameToAdd = "" } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to Bug: If you have ever made a TestFlight build with a higher version number, you won't get any crash nor feedback reports from users for lower versions!
I understand the mistake was a long time ago (build 55). IMHO, it is not a bug but an intended policy of AppStore to make sure users are not confused by release versions that go up and down. So little chance a bug report would lead to any change. Which means we effectively have to double check all the meta information before pushing on the Appstore. Can't you make your new version 2.0.1 with build 211 ? I understand it is not the best, but that's the only option I know. Last hope: contact developers' support to see if they can do anything for you ?
Replies
Boosts
Views
Activity
May ’24
Reply to Mirgation from Xcode 14 to Xcode 15
Just complaining about a problem without giving details on the context is not enough to get some help. Where and how did you define type R ? Where do you use it ?
Replies
Boosts
Views
Activity
May ’24
Reply to protocol in swiftUI
Could you tell from where you extracted the screenshot with Path extension ? What is inside the ellipsis ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to "Unexpectedly found nil while unwrapping an Optional value" in URL
If I understand, the error is here: func fetchLink() async { do { url = URL(string: GlobalString().link) let (data, _) = try await URLSession.shared.data(from: url!) If you look at URL documentation, you see that URL(string: _) returns an optional which may be nil (that's what happens in your case) init?(string: String) Creates a URL instance from the provided string. Why is it nil, that's what you have now to investigate. To make your code robust, test for nil: func fetchLink() async { do { url = URL(string: GlobalString().link) if url == nil { print(GlobalString()) // <<-- To understand what happens return // do not continue } let (data, _) = try await URLSession.shared.data(from: url!) // <<-- cannot be nil anymore Do the same by testing post_url if the error is here: let postUrl: URL? = linkResponse.post_url != nil ? URL(string: linkResponse.post_url!) : nil Note: In Swift we avoid using underscore and use camelCase instead. That means post_url should better be postUrl or postURL for instance.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to Yet another change to forum interface. Is it worth it ?
Thanks Quinn. So I'll wait a few more weeks to get accustomed and hopefully appreciate.
Replies
Boosts
Views
Activity
May ’24
Reply to Yet another change to forum interface. Is it worth it ?
Just to test, I reply to my own post. No more possible to edit full width (hiding the preview) ? And the total width has been reduced. It seems a bit awkward to say the least on a 27" screen… If I wanted to post some code, that would really be messy.
Replies
Boosts
Views
Activity
May ’24
Reply to SwiftUI: How do I detect a change in device orientation?
Several simple solutions here: https://forums.developer.apple.com/forums/thread/126878 Did you see it ? But note eskimo's post to strongly discourage to use landscape or portrait information in SwiftUI…
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to Swiftui - Pressing button in a list also actions another button
You have to set buttonStyle (does not work with default value), such as: .buttonStyle(.borderless) // Or some other style So your code: List(am.students) { item in HStack { Text(item.name).font(fancyFont) Spacer() Button(item.casual ? "All Paid" : "Reverse All Paid") { // Issue: pressing this button also results in Remove button action being invoked. item.casual = !item.casual } .buttonStyle(.borderless) // <<-- ADD THIS Or some other style .foregroundColor(Color(white: 0.15)) .padding(3) .overlay( RoundedRectangle(cornerRadius: 5) .stroke(Color(white: 0.5), lineWidth: 3) ) Spacer().frame(width: 40) Button("Remove") { Task { await am.delete(student: item) } } .buttonStyle(.borderless) // <<-- ADD THIS Or some other style .foregroundColor(Color(white: 0.15)) .frame(width: 80) .padding(3) .overlay( RoundedRectangle(cornerRadius: 5) .stroke(Color(white: 0.5), lineWidth: 3) ) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to How might I get didSet behaviour on an AppStorage var?
Surprising. I tested the code proposed here and it works: https://stackoverflow.com/questions/63171806/willset-not-being-called-on-swiftuis-new-appstorage-property struct DemoAppStorageDidSet: View { @AppStorage("codeResult") var codeResult: String = "Default" { // << default value willSet { print("willSet: \(newValue)") } didSet { print("didSet: \(oldValue)") } } var body: some View { VStack { Text("Code Result: \(codeResult)") Divider() Button("AppStore Update") { self.codeResult = "AppStore" // << activates willSet/didSet !! } Divider() Button("UserDefaults Update") { UserDefaults.standard.set("UserDefaults", forKey: "codeResult") } } } }   Tapping "AppStore Update" logs as expected: willSet: AppStore didSet: Default Tapping a second time: willSet: AppStore didSet: AppStore So please show your complete code that does not work (maybe stupid question: are you sure the console is visible for log ?)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to FORM PROBLEMS
That's a limit of SwiftUI: a view cannot have more than 10 subviews (here sections). There is a workaround: group up to 10 sections in a Group Form { Group { Section { } Section { } // up to 10 sections } Group { Section { } Section { } // up to 10 sections } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Reply to SF Symbol
Where did you see this symbol ? In an Apple's app or another app ? I searched also for circle and for dotted. Could not find it either. moon.circle is relatively close to this. But not the same.
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
May ’24