Post

Replies

Boosts

Views

Activity

Reply to SwiftUI does not manage two NavigationLinks in a single list row
I may have found a simple solution. Problem comes from List which manages interactions with rows on its own, creating the mess. I just replaced List by a ScrollView, to get very similar display (except the ">" after button, but works OK for each link. No need either for buttonStyle. struct ContentView: View { var body: some View { NavigationView { // List { ScrollView { ForEach(0..<10) { index in HStack { Spacer() NavigationLink(destination: DestinationView1(item: index)) { Text("Navigate to View 1") .padding() .background(Color.blue) .foregroundColor(.white) .cornerRadius(8) } // .buttonStyle(PlainButtonStyle()) // Not needed Spacer() NavigationLink(destination: DestinationView2(item: index)) { Text("Navigate to View 2") .padding() .background(Color.green) .foregroundColor(.white) .cornerRadius(8) } // .buttonStyle(PlainButtonStyle()) // Not needed Spacer() } .padding(.vertical, 5) } } .navigationBarTitle("Navigation Links") } } } struct DestinationView1: View { var item: Int var body: some View { Text("Destination View 1 for item \(item)") .navigationBarTitle("View 1", displayMode: .inline) } } struct DestinationView2: View { var item: Int var body: some View { Text("Destination View 2 for item \(item)") .navigationBarTitle("View 2", displayMode: .inline) } }
Jun ’24
Reply to SwiftUI Picker Label
Picker label does not show except in some conditions. You have to find a work around to display the label independently. Get details here: https://stackoverflow.com/questions/69381385/swiftui-custom-picker-label-not-rendering
Topic: UI Frameworks SubTopic: SwiftUI 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:
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