Post

Replies

Boosts

Views

Activity

Reply to Change background SwiftUI
What I want is (for example) when I tap on the Text(arr[0]) at line 12 the background becomes grey and if I tap on Text(arr[1]), Text(arr[0]) returns to be normal background and Text(arr[1]) becomes grey Why don't you put .background modifier to Text? struct PickerView: View { &#9;&#9; &#9;&#9;var arr: [String] = ["Easy", "Medium", "Hard"] &#9;&#9;var h: CGFloat = 50 &#9;&#9;var w: CGFloat = 320 &#9;&#9;@Environment(\.colorScheme) var colorScheme &#9;&#9;var normalColor: Color {colorScheme == .dark ? .black : .white} &#9;&#9; &#9;&#9;@ObservedObject var input: UserInput &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;HStack(spacing: 40){ &#9;&#9;&#9;&#9;&#9;&#9;ForEach(0..<arr.count) { i in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack(spacing: 25) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(arr[i]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.bold() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.onTapGesture { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;input.indi = i &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print(i) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(i == input.indi ? Color.gray : normalColor) //<- &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;if i < arr.count - 1 { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Divider() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(height: 25) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;}.padding() &#9;&#9;&#9;&#9;.clipShape(RoundedRectangle(cornerRadius: 16, style: .continuous)) &#9;&#9;&#9;&#9;.overlay( &#9;&#9;&#9;&#9;&#9;&#9;RoundedRectangle(cornerRadius: 16) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.stroke(Color.gray, lineWidth: 3) &#9;&#9;&#9;&#9;) &#9;&#9;} }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to How do you run AVSpeechSynthesizer from command-line Swift on MacOS?
You need to keep your process alive until the speech is finished. Please try something like this: import Foundation import AVFoundation class MyAVSpeechSynthesizerDelegate: NSObject, AVSpeechSynthesizerDelegate { &#9;&#9;func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) { &#9;&#9;&#9;&#9;print("Done.") &#9;&#9;&#9;&#9;exit(0) &#9;&#9;} } print("Hello, World!") var synthesizer = AVSpeechSynthesizer() let utterance = AVSpeechUtterance(string: "Hello World!") utterance.voice = AVSpeechSynthesisVoice(identifier: "com.apple.speech.synthesis.voice.samantha.premium") utterance.rate = 0.5 let myDelegate = MyAVSpeechSynthesizerDelegate() synthesizer.delegate = myDelegate synthesizer.speak(utterance) RunLoop.main.run()
Topic: App & System Services SubTopic: General Tags:
Jan ’21
Reply to PHPhotoLibrary.performChanges(_:completionHandler:) not escaping?!
How come completionHandler closure is not declared as escaping Generally, two closure parameters may be independent each other, so one is escaping and the other is non-escaping would be possible. But in this case, completionHandler is also escaping. In Swift (at least, in recent Swifts, I do not know where the clear documentation about this exists), Optional closure type is implicitly treated as escaping. In fact, Xcode shows an error writing something like this: &#9;&#9;func myFunc(_ completion: (Bool, Error?)->Void) { //<- non-escaping, non-Optional closure &#9;&#9;&#9;&#9;library.performChanges({ &#9;&#9;&#9;&#9;&#9;&#9;//... &#9;&#9;&#9;&#9;}, completionHandler: completion) //-> Passing non-escaping parameter 'completion' to function expecting an @escaping closure &#9;&#9;} If I define a function with two closure parameters where the second closure is called after the first one is finished, and the first closure is escaping, does the second closure have to be escaping as well?  Two closure parameter may be independent. If you can assure that the second closure may only be called in the execution context of the method (meaning it may never executed after completion of the method) it has no need to be escaping. (Though, the second closure is called after the first one is finished and the second closure may only be called in the execution context of the method leads a conclusion that the first parameter also has no need to be escaping.)
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Issue with networking and Codable class
It depends on what the API does, but, if the API returns String, you may need to prepare a type accepting String. Add another struct to receive the value from the API: struct NFCDataSecAPI: Codable { &#9;&#9;var lastName: String = "" &#9;&#9;var firstName: String = "" &#9;&#9;var age: String = "0" } Or use only this one and change other parts of your code.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Issue with networking and Codable class
Could it be because I'm not using the main thread to POSTand GET from the API ?  I do not think so. You code is disposing the most important error info, so nothing sure. (UPDATE) Seems you have updated your last post. I can't understand, now, why my class is not updated with the retrieved data (2). Where is the code updating your class?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Button to Multiple Two Variables and Return Result
Your Button action on line 20...25 does nothing. You declare a local function (line 21...24) inside it, but it is NOT used. Please clarify on which line the error occurs and show all the definitions (for example BOIEquations) which are involved in the error. It seems you do not understand the difference of defining a function and calling it. Better learn basics of Swift language first.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Parse XML in SwiftUI
Your code is too primitive, so I cannot think of what to ask. So, just some general advice: XML may contain information in various ways. You may not find any third party libraries working unless the XML is designed for a particular library. In Apple's frameworks, there is XMLParser. Which is so called a SAX-based parser, you may need to write plenty of code depending on the content of the XML.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Button to Multiple Two Variables and Return Result
I've tried making the function in other parts of the code, but then I start to get errors saying that variables aren't in the scope.  That's because you have a local variable storedRanSampTons in your VStack, do not move the function definition but move the variable declaration. had a good enough understanding of the basics of Swift language to get this far.  I'm not saying you have learnt nothing, but it was not enough seeing your code. Why are you writing like this if you have enough understanding of the basics?          Text("Random Sample Tonnage: \(sublotTonnage) ")
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to update to required xcode version 12
This is not a good place to express disappointment to Apple. (Though, I guess many developers are feeling the same as you.) Better send a feedback - https://developer.apple.com/bug-reporting/ representing what you expect to Apple. Many of the feedbacks may be left untouched, but the number would affect and better than just complaining here.
Jan ’21
Reply to Button to Multiple Two Variables and Return Result
That is what was covered in those tutorials as how to pull information from a variable to print on the screen of an app. Is there a better way to do it that those didn't cover because all of them I've done on Udemy and Ray Weinderlich's site all did it that way? Seems you are too early for Udemy or Ray Wenderlich's site. I have never seen a site using function name in a String interpolation of Text.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Rss
There may be many ways to update text weekly, but I do not understand what you mean by like an res feed. Can you explain what you want to do in detail without using the word RSS?
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21