Post

Replies

Boosts

Views

Activity

Reply to Xcode freezes when I click on LaunchScreen.storyboard
Probably, when you created the project, you did not define it correctly. You should: create new project select iOS App in the first screen in the next screen where you enter product name, select Storyboard as interface (not SwiftUI) and UIKit App Delegate as lifecycle and Swift as language. Does it work this way ? If so, don't forget to close the thread.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Why is a Class faster in SwiftUI than a Struct? (with example)
I tested (with your OP code) in Simulator with Xcode 12.2 and did not notice any performance issue you are mentioning. Can you explain and give figures ? Anyway, class should be faster because it does not call all the mechanisms to update the UI when its state changes. But that is the core value of SwiftUI ! Question is : is this performance difference, if any, significant enough from a user perspective ? Main difference is that slider with class is not updated until I move the Struct slider. And that's normal.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Create a blinking label
I did this with a UIView extension extension UIView {  &#9;&#9;func flashIt(repeated: Int, cycleTime: Double, delayed: Double = 5.0) { &#9;&#9;&#9;&#9;if repeated < 0 { return } &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;let initAlpha = self.alpha &#9;&#9;&#9;&#9;UIView.animate(withDuration: cycleTime,&#9;//Time duration &#9;&#9;&#9;&#9;&#9;&#9;delay: delayed, &#9;&#9;&#9;&#9;&#9;&#9;options:[.allowUserInteraction, .curveEaseInOut, .autoreverse, .repeat], &#9;&#9;&#9;&#9;&#9;&#9;animations: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;UIView.setAnimationRepeatCount(Float(repeated)) // repeat 3 times. &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.alpha = 0.1&#9;&#9;// Not 0.0, to allow user interaction &#9;&#9;&#9;&#9;}, &#9;&#9;&#9;&#9;&#9;&#9;completion: { (done: Bool) in self.alpha = initAlpha } ) &#9;&#9;} } In your case, instead of setting the alpha, just set the background color. And restore it in completion.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to MacBook Pro Early 2015 Keeps Rebooting after Big Sur update
According to Apple doc, Big Sur can be used on MBP Retina models of late 2013 and after. So no reason not to work. https://support.apple.com/en-us/HT211238 They also indicate that you need 35 or 45 GB available to update. Did you get this room ? How much RAM have you got ? If not enough (less that 16 GB), that could explain some over activity (but not the crashes). Otherwise, best is to contact Apple support.
Topic: App & System Services SubTopic: Core OS Tags:
Jan ’21
Reply to Cannot draw ViewController on MacOS 10.10 and 10.11
OK, that's not in IB hierarchy but in the debug. Effectively, NSThemeFrame is the superview of the NSWindow content (holding the title for instance). So that's likely not the problem. Have you checked the constraints for positioning the objects ? Try to add constraints for leading and top position in their view.
Topic: UI Frameworks SubTopic: AppKit Tags:
Jan ’21
Reply to Fetching from JSON SwiftUI
but when I access the properties of my struct it tells me Value of Type "Name Of The Struct" has no member "name of the property" Do you mean "Matches has no member someName" ? Could you show the JSON you get to check the coding keys ? Why don't you define CodingKeys ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Fetching from JSON SwiftUI
OK, here is an extract from json You could have made the effort to get it and post it yourself, isn't it ? { &#9;"name": "Serie A 2020/21", &#9;"matches": [ &#9;&#9;{ &#9;&#9;&#9;"round": "1^ Giornata", &#9;&#9;&#9;"date": "2020-09-19", &#9;&#9;&#9;"team1": "ACF Fiorentina", &#9;&#9;&#9;"team2": "Torino FC", &#9;&#9;&#9;"score": { &#9;&#9;&#9;&#9;"ft": [ &#9;&#9;&#9;&#9;&#9;1, &#9;&#9;&#9;&#9;&#9;0 &#9;&#9;&#9;&#9;] &#9;&#9;&#9;} &#9;&#9;}, &#9;&#9;{ &#9;&#9;&#9;"round": "1^ Giornata", &#9;&#9;&#9;"date": "2020-09-19", &#9;&#9;&#9;"team1": "Hellas Verona", &#9;&#9;&#9;"team2": "AS Roma", &#9;&#9;&#9;"score": { &#9;&#9;&#9;&#9;"ft": [ &#9;&#9;&#9;&#9;&#9;3, &#9;&#9;&#9;&#9;&#9;0 &#9;&#9;&#9;&#9;] &#9;&#9;&#9;}, &#9;&#9;&#9;"status": "AWARDED" &#9;&#9;}, &#9;&#9;{ &#9;&#9;&#9;"round": "1^ Giornata", &#9;&#9;&#9;"date": "2020-09-20", &#9;&#9;&#9;"team1": "Parma", &#9;&#9;&#9;"team2": "SSC Napoli", &#9;&#9;&#9;"score": { &#9;&#9;&#9;&#9;"ft": [ &#9;&#9;&#9;&#9;&#9;0, &#9;&#9;&#9;&#9;&#9;2 &#9;&#9;&#9;&#9;] &#9;&#9;&#9;} &#9;&#9;}, The error is on lines 30 and 35 where you pass an array. Just pass: &#9;&#9;@Published var users = UserItalia(matches: []) and &#9;&#9;&#9;&#9;&#9;&#9;.decode(type: UserItalia.self, decoder: JSONDecoder()) You could also decode the complete JSON: struct Score: Decodable, Hashable { &#9;&#9;var ft: [Int]? } struct Matches: Decodable, Hashable { &#9;&#9;var round: String? &#9;&#9;var date: String? &#9;&#9;var team1: String? &#9;&#9;var team2: String? &#9;&#9;var score: Score? &#9;&#9;var status: String? } struct UserItalia: Decodable, Hashable { &#9;&#9;var name: String? &#9;&#9;var matches: [Matches]? }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Fetching from JSON SwiftUI
'ForEach' requires that 'UserItalia' conform to 'RandomAccessCollection' Of course, UserItalia is not an array. You need to understand better what your data structures are. networkController.users is UserItalia type. What you want to access are matches, isn't it ? So, you should write something like this &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach(networkController.users.matches ?? [], id: \.self){ match in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;GroupBox(label: Text(match.round ?? ""), content: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;VStack{ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(match.team1 ?? "") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}).padding() I tested and it works (iOS 14.2). If that's OK, don't forget to close the thread on this answer, otherwise please detail the exact error you get.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Fetching from JSON SwiftUI
If it works, thanks to mark this answer as correct. From there you can also print the score: ForEach(networkController.users.matches ?? [], id: \.self){ match in GroupBox(label: Text(match.round ?? ""), content: { VStack { HStack { Text(match.team1 ?? "") Text(" - ") Text(match.team2 ?? "") } HStack { // THIS HStack is not needed, unless you want to add some other text in line. Text(match.score == nil ? "" : "\(match.score!.ft![0]) - \(match.score!.ft![1])") } } }).padding()
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Navigation Bar Back Button
The way I do this usually: create a UIBarButtonItem in IB in the "back place"     @IBOutlet fileprivate weak var backButton: UIBarButtonItem! Then set in viewDidLoad &#9;&#9;&#9;&#9;backButton.tintColor = defaultBlueColor // if needed ; I defined defaultBlueColor elsewhere &#9;&#9;&#9;&#9;backButton.title = NSLocalizedString("Come back", comment: "")
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21