Post

Replies

Boosts

Views

Activity

Reply to Building with Xcode 12.5 fails with CompileSwift failed with a nonzero exit code and Segmentation fault: 11
If that may help… I once had a segmentation fault 11. Reason was: In a struct defined as: struct L { var u1: UInt64 var u2: UInt64 var u3: UInt64 var u4: UInt64 } I defined a subscript extension L {     subscript (j: Int, h: Int) - Bool? { } As far as I remember, the fault occurred if I called var lib  : [L]? if lib[j,h] { } instead of unwrapping: if lib![j,h] { } Hope that may help.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to NSSavePanel Error
The app's entitlements does NOT have "com.apple.security.files.user-selected.read-write" Note that you could also add manually this entry in the entitlements plist (auto completion works there as well as you type com.apple.security.files.user). So that was the root cause. Don't forget to close the thread.
Topic: UI Frameworks SubTopic: AppKit Tags:
Apr ’21
Reply to Thread 1: breakpoint 1.1 2.1
Are you sure you have not set a direct breakpoint there ? It occurred to others: https://developer.apple.com/forums/thread/39283 or https ://forums.raywenderlich. com/t/thread-1-breakpoint-1-1-2-1/41631 Or have you defined a breakpoint elsewhere ? Can you resume execution after breakpoint ? You should also try an option- clean build folder, in case. In anycase, look at the breakpoint panel at the left of Xcode window to see all the breakpoints you have set, and remove all.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to min() and max() function
Don't use min and max for this. For instance, create a func to test validity: func isValidNumberOfPlayers(_ nb: Int) -> Bool { &#9;return nb > 0 && nb <= 10 } Then, when you create or read the list of players, for instance in an array with their names: var players: [String] = [] // You populate the array somewhere In the func where you declare the players, check the value, call if !isValidNumberOfPlayers(players.count) { print("number of players is not correct") // And do whatever you need to do } If you want to give a more precise test result, you could do this: enum PlayersCheckState { &#9;&#9; case ok &#9;&#9; case null &#9;&#9; case tooMany } func isValidNumberOfPlayers(_ nb: Int) -> PlayersCheckState { &#9;&#9;switch nb { &#9;&#9;case ...0&#9;: return .null &#9;&#9;case 1...10: return .ok &#9;&#9;default&#9;&#9;: return .tooMany &#9;&#9;} } Then call &#9;&#9;switch isValidNumberOfPlayers(playersCount) { &#9;&#9;case .null : print("No player") &#9;&#9;case .tooMany: print("too many players") &#9;&#9;case .ok: break&#9;&#9;//&#9;do whatever you need to do here &#9;&#9;}
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to healthkit query
Have you tried removing @escaping for RCTPromiseRejectBlock ? @objc func updateStepsCount(_ &#9;&#9;resolve: @escaping RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) { &#9;&#9;checkNotificationEnabled { enabled in &#9;&#9;&#9;&#9;resolve(enabled) &#9;&#9;} } // Or maybe in your case @objc func updateStepsCount(_ statisticsCollection: HKStatisticsCollection, _ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: (RCTPromiseRejectBlock) -> Void) { See: https://stackoverflow.com/questions/59732722/swift-how-can-i-call-my-function-inside-completion-body This may be of interest as general discussion: https://forums.swift.org/t/implicit-escaping-of-closures-via-objective-c/12025
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Local Notification
Try UNUserNotificationCenter.current().getNotificationSettings { (settings) in &#9;if settings.authorizationStatus == .authorized { &#9;&#9;// Notifications are allowed &#9;} &#9;else { &#9;&#9;// Either denied or notDetermined &#9;} } As defined here here: https://stackoverflow.com/questions/46664177/check-whether-user-notifications-are-enabled-after-uilocalnotification-deprecati
Apr ’21
Reply to Protocol Not Working
@ZoneX It is very difficult to help if you don't do exactly what we propose. I proposed: override func prepare(for segue: UIStoryboardSegue, sender: Any?) { &#9;print("segue identifier", segue.identifier) &#9;if segue.identifier == "r" { &#9;&#9;let hockeyDetailVC: HockeyDetailVC = segue.destination as! HockeyDetailVC &#9;&#9;hockeyDetailVC.delegate = self &#9;} } and tell what you get. If you get something different from segue identifier r such as segue identifier R or segue identifier SomeString that means that "r" is not the identifier of this segue (or you don't call the right segue). Then change "r" by what you got here after "segue identifier" And what you did is very different for testing purpose &#9;override func prepare(for segue: UIStoryboardSegue, sender: Any?) { &#9;if segue.identifier == "r" { &#9;&#9;print("segue identifier", segue.identifier) // You put in the if that we know is not called ! It is key to check you call the RIGHT segue &#9;&#9;let hockeyDetailVC: HockeyDetailVC = segue.destination as! HockeyDetailVC &#9;&#9;hockeyDetailVC.delegate = self &#9;&#9;print("destination HockeyDetailVC is", hockeyDetailVC) &#9;} }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Swift functions
Your question is not very clear. Do you want to print (where ?) or do you want to display the matrix on screen in a Label, TextField, TextView ? To print in log, simply do: for x in xo { print(x) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21