Post

Replies

Boosts

Views

Activity

Reply to FPS App crashes when compiling, “Thread 1: Swift runtime failure: Range requires lowerBound <= upperBound” error
FPS App crashes when compiling  I see the following when the compiler runs the line The compiler is a tool to generate a binary, and it is not something to run a code. As far as I know, the error you find is a runtime error which would not be shown in compile-time. Ignoring such terminology problems, it is clear why you see that error: min Engine.Vector x = (Double) 51.75 y = (Double) 0 max Engine.Vector x = (Double) 2 y = (Double) 51.75 The left hand side of the range operator ..< cannot be greater than the right hand side. In your case shown, 51.75 (and Int value of it) is clearly greater than 2. You may need to find all the places you create such Rects in your project and fix them to fulfill the requirement of Range. Or create some sort of extension: public extension Rect { var minX: Double {Swift.min(min.x, max.x)} var maxX: Double {Swift.max(min.x, max.x)} var minY: Double {Swift.min(min.y, max.y)} var maxY: Double {Swift.max(min.y, max.y)} } And use it like this: for y in Int(rect.minY) ..< Int(rect.maxY) { for x in Int(rect.minX) ..< Int(rect.maxX) { self[x, y] = color } }
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’21
Reply to Priority queue in Swift
Is a collection like this available in Swift? I do not think so. At lease, not now. If you want to discuss about some future of Swift, you should better visit swift.org . You can find Get Involved! part at the bottom of this article. Introducing Swift Collections
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’21
Reply to Trouble with @escaping Competion Handler when passing data in a shared data container
Any advice would be greatly appreciated! If you can target your app for iOS 15+ and are planning to release it after the released version of Xcode 13 is out, you may try using new async/await feature. Meet async/await in Swift Use async/await with URLSession (There are more session videos about async/await and I recommend to watch all if you have enough time.) If you need to make your app target iOS 14.x and earlier, working with completion handler would be necessary. I assume your loadInitialFireMapData is working fine in normal cases. (Hope you are not ignoring any warnings.) But it has some flaws considering error cases: It ignores some error cases without showing any debug info It does not call completion handler on errors You should better pass an Optional<Error> to the completion handler to indicate error cases. I would write it as follows: class FireDataManager { enum Errors: Error { case urlInvalid case dataIsNil } func loadInitialFireMapData(completion: @escaping (Error?) -> Void) { //<- guard let url = URL(string: "https://opendata.arcgis.com/datasets/68637d248eb24d0d853342cba02d4af7_0.geojson") else { completion(Errors.urlInvalid) return } URLSession.shared.dataTask(with: url) {data, response, error in if let error = error { print("FireMap URL Session error: ", error) //Use `error` instead of `error.localizedDescription` to show debug info completion(error) return } guard let data = data else { completion(Errors.dataIsNil) return } do { let features = try MKGeoJSONDecoder().decode(data) .compactMap { $0 as? MKGeoJSONFeature } let validWorks = features.compactMap(Fire.init) DataContainer.shared.fires.append(contentsOf: validWorks) DataContainer.shared.totalFireCount = validWorks.count print("Fire Data Manager Count of Total Fires: ", DataContainer.shared.totalFireCount) DispatchQueue.main.async { completion(nil) //<- no error here } } catch let error { print("FireMap decoding error: ", error) completion(error) } } .resume() } } In this case, meaning the type of completion is (Error?)->Void, you need to write a closure like { (error: Error?)->Void in ... } or in a simplified form { error in ... } . So, the caller side code would be something like this: class ViewController: UIViewController, CLLocationManagerDelegate { @IBOutlet weak var fireStatusLabel: UILabel! let dataContainer = DataContainer.shared let fireDataManager = FireDataManager() override func viewDidLoad() { super.viewDidLoad() //Retrieve Fire API data from Fire Data Manager fireDataManager.loadInitialFireMapData (completion: { error in if let error = error { print(error) return } self.fireStatusLabel.text = "\(DataContainer.shared.totalFireCount) fires within 100 miles of your location." }) //... } //... } (I renamed FireStatusLabel to fireStatusLabel as only type names start with Capital letter in Swift. If you have any reasons you cannot rename it, please re-interpret the lines with fireStatusLabel.) Or you can use the trailing closure notation like this: fireDataManager.loadInitialFireMapData { error in //<- no opening parenthesis here if let error = error { print(error) return } self.fireStatusLabel.text = "\(DataContainer.shared.totalFireCount) fires within 100 miles of your location." } //<- no closing parenthesis Please try.
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’21
Reply to Form vs Vstack for SwiftUI for iOS
So my question is, is there any reason I should put up with the trouble and use Form? In my opinion, Form is a collection of bunch of styles or behaviors which Apple's designer thinks is appropriate for input forms. So, many of the modifiers do not work as expected for Form or components inside Form. If you want to make many components customized, not using Form seems to be a practical way than hacking the implementation details. From what I can tell, there don't seem to be any real benefits, right? Form is a good container if you want to implement the default styles or behaviors. Seems you do not think it a real benefit, but not all developer would think as you do. One clear thing is, you can have your own opinion.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’21
Reply to FPS App crashes when compiling, “Thread 1: Swift runtime failure: Range requires lowerBound <= upperBound” error
FPS App crashes when compiling  I see the following when the compiler runs the line The compiler is a tool to generate a binary, and it is not something to run a code. As far as I know, the error you find is a runtime error which would not be shown in compile-time. Ignoring such terminology problems, it is clear why you see that error: min Engine.Vector x = (Double) 51.75 y = (Double) 0 max Engine.Vector x = (Double) 2 y = (Double) 51.75 The left hand side of the range operator ..< cannot be greater than the right hand side. In your case shown, 51.75 (and Int value of it) is clearly greater than 2. You may need to find all the places you create such Rects in your project and fix them to fulfill the requirement of Range. Or create some sort of extension: public extension Rect { var minX: Double {Swift.min(min.x, max.x)} var maxX: Double {Swift.max(min.x, max.x)} var minY: Double {Swift.min(min.y, max.y)} var maxY: Double {Swift.max(min.y, max.y)} } And use it like this: for y in Int(rect.minY) ..< Int(rect.maxY) { for x in Int(rect.minX) ..< Int(rect.maxX) { self[x, y] = color } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Priority queue in Swift
Is a collection like this available in Swift? I do not think so. At lease, not now. If you want to discuss about some future of Swift, you should better visit swift.org . You can find Get Involved! part at the bottom of this article. Introducing Swift Collections
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Cannot convert value of type 'EventsTrigger' to expected argument type 'String?
Please share the solution you have found.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Trouble with @escaping Competion Handler when passing data in a shared data container
Any advice would be greatly appreciated! If you can target your app for iOS 15+ and are planning to release it after the released version of Xcode 13 is out, you may try using new async/await feature. Meet async/await in Swift Use async/await with URLSession (There are more session videos about async/await and I recommend to watch all if you have enough time.) If you need to make your app target iOS 14.x and earlier, working with completion handler would be necessary. I assume your loadInitialFireMapData is working fine in normal cases. (Hope you are not ignoring any warnings.) But it has some flaws considering error cases: It ignores some error cases without showing any debug info It does not call completion handler on errors You should better pass an Optional<Error> to the completion handler to indicate error cases. I would write it as follows: class FireDataManager { enum Errors: Error { case urlInvalid case dataIsNil } func loadInitialFireMapData(completion: @escaping (Error?) -> Void) { //<- guard let url = URL(string: "https://opendata.arcgis.com/datasets/68637d248eb24d0d853342cba02d4af7_0.geojson") else { completion(Errors.urlInvalid) return } URLSession.shared.dataTask(with: url) {data, response, error in if let error = error { print("FireMap URL Session error: ", error) //Use `error` instead of `error.localizedDescription` to show debug info completion(error) return } guard let data = data else { completion(Errors.dataIsNil) return } do { let features = try MKGeoJSONDecoder().decode(data) .compactMap { $0 as? MKGeoJSONFeature } let validWorks = features.compactMap(Fire.init) DataContainer.shared.fires.append(contentsOf: validWorks) DataContainer.shared.totalFireCount = validWorks.count print("Fire Data Manager Count of Total Fires: ", DataContainer.shared.totalFireCount) DispatchQueue.main.async { completion(nil) //<- no error here } } catch let error { print("FireMap decoding error: ", error) completion(error) } } .resume() } } In this case, meaning the type of completion is (Error?)->Void, you need to write a closure like { (error: Error?)->Void in ... } or in a simplified form { error in ... } . So, the caller side code would be something like this: class ViewController: UIViewController, CLLocationManagerDelegate { @IBOutlet weak var fireStatusLabel: UILabel! let dataContainer = DataContainer.shared let fireDataManager = FireDataManager() override func viewDidLoad() { super.viewDidLoad() //Retrieve Fire API data from Fire Data Manager fireDataManager.loadInitialFireMapData (completion: { error in if let error = error { print(error) return } self.fireStatusLabel.text = "\(DataContainer.shared.totalFireCount) fires within 100 miles of your location." }) //... } //... } (I renamed FireStatusLabel to fireStatusLabel as only type names start with Capital letter in Swift. If you have any reasons you cannot rename it, please re-interpret the lines with fireStatusLabel.) Or you can use the trailing closure notation like this: fireDataManager.loadInitialFireMapData { error in //<- no opening parenthesis here if let error = error { print(error) return } self.fireStatusLabel.text = "\(DataContainer.shared.totalFireCount) fires within 100 miles of your location." } //<- no closing parenthesis Please try.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Cannot convert value of type 'EventsTrigger' to expected argument type 'String?
Unless any clarification about what you want to do, there is no clue to find what will be needed.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to AttributedString with Markdown in UILabel doesn't render any attributes?
The parameter label markdown: is missing in your code.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to AttributedString with Markdown in UILabel doesn't render any attributes?
Please include code as text, do not use image.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to getting Error While using Date picker class ActionSheetDatePicker.init
Thanks for showing your code. But codes in comments cannot be properly formatted and hard to read. Can you use Your Answer to show your code? (Please format it as Code Block, not Add Text.)
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Cannot convert value of type 'EventsTrigger' to expected argument type 'String?
It has 4 parameters and the second parameter would be imported into Swift as String?. What do you want to pass to rAddress? And one more, the third parameter needs to be an instance of class conforming to ServiceCallback. Your EventsTrigger does not seem to conform to ServiceCallback.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to React native build failure
React Native is not a framework of Apple's. You should better contact to the author of it or find a supporting site or a community site of it, to get better responses sooner.
Replies
Boosts
Views
Activity
Jun ’21
Reply to Cannot convert value of type 'EventsTrigger' to expected argument type 'String?
Depends on how NewService and its initializer is defined. Can you show the definition of it?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to getting Error While using Date picker class ActionSheetDatePicker.init
As far as I know there are no class named ActionSheetDatePicker in Apple's framework. Can you tell me how it is defined? And showing teared fragments of code would not be helpful to find what's going on. Can you show whole class(es) or method(s) in one piece?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Value of type 'UISearchBar' has no member 'showLoading'
As the error message is clearly stating, UISearchBar does not have a method named showLoading. Did you define it by yourself? Where? How? And what is search (or self.search) in your code?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Form vs Vstack for SwiftUI for iOS
So my question is, is there any reason I should put up with the trouble and use Form? In my opinion, Form is a collection of bunch of styles or behaviors which Apple's designer thinks is appropriate for input forms. So, many of the modifiers do not work as expected for Form or components inside Form. If you want to make many components customized, not using Form seems to be a practical way than hacking the implementation details. From what I can tell, there don't seem to be any real benefits, right? Form is a good container if you want to implement the default styles or behaviors. Seems you do not think it a real benefit, but not all developer would think as you do. One clear thing is, you can have your own opinion.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to What is a scope declaration in swift programming language ?
You are leaving many of the threads untouched even if you get replies. You should respond to the comments or answers before starting a new question.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21