Post

Replies

Boosts

Views

Activity

Reply to How do I stop 'The compiler is unable to type-check this expression in reasonable time'
now I get more errors Generally, when you get The compiler is unable to type-check this expression, there may be multiple type-related errors, that Swift compiler could not detect. So, while breaking up, you may find more and more errors. Your definition of body is too large. You should better check errors every time you add lines into body. The same original error You need to split up codes until the same error is not generated Cannot find 'launch' in scope (line 5) Cannot find 'launch' in scope (line 13) You use launch in your definition of bodyGroup, that should be declared inside the scope of bodyGroup. But it does not exist. You may need to make it a function instead of computed property:     func bodyGroup(_ launch: Launch) -> some View { 				//... 		} And use it as:                                             bodyGroup(launch) You may need to repeat this process.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Read image from asset catalog
I drag a image.jpg into the assets.xcassets. Then you have added an Image Set of name image to the Asset catalogue, not Data Set. You may need to use UIImage.init(named:). Or else if you want to use NSDataAsset, you need to add a Data Set.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Read image from asset catalog
is "UIImage(named:)" the only way to retrieve image data from image set in assets catalog?  As far as I know, YES. UIImage is a bit expensive for sizing and to resizing.  What are you trying to do? Does it make a significant difference between UIImage and Data of the image?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Failed to produce diagnostic for expression; please file a bug report
Your code shown is sort of broken, so cannot say something sure for all ranges of your code. (Better care about code formatting if you want to let readers help solving your issue.) But you need to fix ScanView_Previews at least: struct ScanView_Previews: PreviewProvider { static let float2 : Float = 0.2 static var previews: some View { ScanView(los: .constant(float2), los2: .constant(float2)) } } If you have other issues with your code, you may need to show more info. Please show all the relevant code (OrientationInfo, LidarViewModel, Session, ScanLidarButtons and ScanLidarButtonsMobile, there may be more), well formatted. (Use the Code block icon `` properly.)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Xcode coming to iPad Pro
all kind of people are talking about iOS apps coming to Mac OS and Mac apps coming to iPad M1 Macs have a feature to run iOS apps, but M1 iPads do not have features to run macOS apps. Generally M1 is just a name for marketing and is very similar to A-something. because the m1 chip can run it easily Your because is based on a false assumption. Running macOS apps is not so easy whether M1 is used or not. You can find many threads discussing Xcode on iPad, for example Xcode for iPad Pro - https://developer.apple.com/forums/thread/17585. I do expect Xcode on iPad, but do not know Apple might be planning it or not. You can send a feature request using Apple's Feedback Assistant.
Apr ’21
Reply to How to limit my numbers in Swift
What I have to do now ?  Have in mind what would be the right usage of this site. Have you read this article? Apple Developer Forums - https://developer.apple.com/support/forums/ How this site works and how you should use this site are described there. Please read it carefully if not yet. Undo is not supported in this site, so you should better consider taking enough time when doing things on this site. Especially, please think for future readers. Marking SOLVED on the right solution would benefit for the future readers suffering the same issue.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to How to limit my numbers in Swift
lives represents health points attack function is the code that my characters can loses health points heal function is the code that my characters can gains health points You can write something like this: &#9;&#9;func heal(anotherCharacter: Character){ &#9;&#9;&#9;&#9;anotherCharacter.lives += 20 &#9;&#9;&#9;&#9;if anotherCharacter.lives > 100 { &#9;&#9;&#9;&#9;&#9;&#9;anotherCharacter.lives = 100 &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9;func attack(otherCharacter: Character){ &#9;&#9;&#9;&#9;otherCharacter.lives -= power &#9;&#9;&#9;&#9;if otherCharacter.lives < 0 { &#9;&#9;&#9;&#9;&#9;&#9;otherCharacter.lives = 0 &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;//If `power` can never be negative, the following check is not needed &#9;&#9;&#9;&#9;if otherCharacter.lives > 100 { &#9;&#9;&#9;&#9;&#9;&#9;otherCharacter.lives = 100 &#9;&#9;&#9;&#9;} &#9;&#9;} Or like this, if you prefer using min, max as specified in your other thread: &#9;&#9;func heal(anotherCharacter: Character){ &#9;&#9;&#9;&#9;anotherCharacter.lives = min(100, anotherCharacter.lives + 20) &#9;&#9;} &#9;&#9;func attack(otherCharacter: Character){ &#9;&#9;&#9;&#9;otherCharacter.lives = min(100, max(0, otherCharacter.lives + power)) &#9;&#9;}
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Swift execute code after return, unbelievable!!
Compiling the shown code, Xcode showed this warning: Expression following 'return' is treated as an argument of the 'return' The two line is treated as: &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;return print("what?") In Swift, return statement in a Void function can return only one specific value Void(). (An instance of Void, which is equivalent as the empty tuple ().) And the return type of print is Void, which means it returns Void(). Thus, the result of calling print("what?") can be a return value of Void function as you see.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Networking error management
Also, why can't I implement throwsin my function when it is throwing ? If you declare your connect as throws, it should: return normally return with error (when error thrown) The completion handler of dataTask is executed after connect returned. This is why I would like to implement a throw scenario to my request If you are having such use case in mind, completion handler pattern might be easier: &#9;&#9;func connect(url: String, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; onError errorHandler: @escaping (Error?)->Void) { //<- &#9;&#9;&#9;&#9;let encoded: Data &#9;&#9;&#9;&#9;do { &#9;&#9;&#9;&#9;&#9;&#9;encoded = try JSONEncoder().encode(connexion) &#9;&#9;&#9;&#9;} catch { &#9;&#9;&#9;&#9;&#9;&#9;print("Fail to encode newMed: \(error)") &#9;&#9;&#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;let url = URL(string: "/api/\(url)")! &#9;&#9;&#9;&#9;var request = URLRequest(url: url) &#9;&#9;&#9;&#9;request.setValue("application/json", forHTTPHeaderField: "Content-Type") &#9;&#9;&#9;&#9;request.httpMethod = "POST" &#9;&#9;&#9;&#9;request.httpBody = encoded &#9;&#9;&#9;&#9;URLSession.shared.dataTask(with: url) { data, res, error in &#9;&#9;&#9;&#9;&#9;&#9;if let error = error { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;errorHandler(error) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;guard let response = res else { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;errorHandler(ConnexionError.invalidServerRes) //<- &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;guard let httpResponse = response as? HTTPURLResponse, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;case 200...299 = httpResponse.statusCode &#9;&#9;&#9;&#9;&#9;&#9;else { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.handleServerError(res!) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;guard let data = data else { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("data is nil") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;let decoder = JSONDecoder() &#9;&#9;&#9;&#9;&#9;&#9;do { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;let json = try decoder.decode(Connexion.self, from: data) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print(json) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.connexion.id = json.id &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.connexion.token = json.token &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.connexion.sessionID = json.sessionID &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.signInSuccess = true &#9;&#9;&#9;&#9;&#9;&#9;} catch { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;let dataString = String(data: data, encoding: .utf8) ?? "Unknown encoding" &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("Invalid response \(error) - \(dataString)") &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;}.resume() &#9;&#9;} And use it as: &#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;self.showGroup = false &#9;&#9;&#9;&#9;&#9;&#9;if connexion.isNotEmpty { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.connect(url: "url", onError: { err in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.showError = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) &#9;&#9;&#9;&#9;&#9;&#9;} else { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.showEmpty = true &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;}) { &#9;&#9;&#9;&#9;&#9;&#9;Text("button") &#9;&#9;&#9;&#9;} Settings :  Sorry, far from I expected. Please show all the customizable things of Postman, including Http Method, Authorization, Header and Body.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to NSSavePanel Error
The app's entitlements does NOT have "com.apple.security.files.user-selected.read-write". How do you add this? Assuming your app is a sandboxed macOS app. Open the project file and choose the Signing &amp; Capabilities tab of the target. You can find the User Selected File in File Access Type of App Sandbox. Check the value is set to Read/Write. The entitlement is automatically managed by this setting.
Topic: UI Frameworks SubTopic: AppKit Tags:
Apr ’21
Reply to Getting CPU type in a Swiftly manner for macOS
natively in swift without having to call a system process? I do not know any Swift classes which returns the exact result as uname -m. One possible way is calling the system function in Swift: var systeminfo = utsname() uname(&amp;systeminfo) let machine = withUnsafeBytes(of: &amp;systeminfo.machine) {bufPtr-String in let data = Data(bufPtr) if let lastIndex = data.lastIndex(where: {$0 != 0}) { return String(data: data[0...lastIndex], encoding: .isoLatin1)! } else { return String(data: data, encoding: .isoLatin1)! } } print(machine)
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Is there any technical reason why Xcode 12.5 cant be installed in Catalina?
Is there any technical reason why Xcode 12.5 cant be installed in Catalina? Apple has never revealed what sort of technical reasons there were when putting some requirements on macOS for new versions of Xcode. Xcode Support page  - https://developer.apple.com/support/xcode We just need to fulfill the requirements provided by Apple if we want to develop apps for the platform founded by Apple. You can write a feature request to Apple that Xcode should support wider range of macOS versions using the Apple's Feedback Assistant.
Apr ’21
Reply to What's wrong with this code? Swipe Gesture not working
it just does not work. You should better clarify what you mean by does not work. You mean any print statements in respondToSwipeGesture(_:) does not output anything? The worst thing in your code is that you are using lazy for the property gestureManager but you are not using gestureManager anywhere in your code. Try something like this: class ViewController: UIViewController { fileprivate lazy var gestureManager: GestureManager = { return GestureManager(vc: self) }() override func viewDidLoad() { super.viewDidLoad() print(gestureManager) //- } } But I would use non-lazy in this case: class ViewController1: UIViewController { fileprivate var gestureManager: GestureManager! override func viewDidLoad() { super.viewDidLoad() gestureManager = GestureManager(vc: self) } } With this change, you would find something happens, but it may not be what you want. As I wrote in another thread of yours - https://developer.apple.com/forums/thread/678795, your GestureManager has some flaws and you have not fixed them all.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Cannot find "self" in scope & Consecutive declarations on a line must be separated by ";".
Why is this happening? Because you are using self in the initial values of instance property declaration. And you are writing executable statements where they are not allowed. why self cannot be found in scope?  You cannot use self in the initial values of instance property declaration in Swift. Isn't SELF supposed to be pointing to GestureManager class? Swift utilizes case-sensitive identifiers. You should better care about letter cases. If you want some words to be emphasized, you can use some markdown features. But the most critically bad thins is this one:  I'm expecting to pass the ViewController to be used in the "target" attribute When you use target-action pattern, the target and the action needs to be consistent. If you pass self.vc to target:, you need to pass an instance method of self.vc to action:. The right fix may depend on the usage of the class GestureManager, but one possible fix would be something like this: class GestureManager { var vc: UIViewController? @objc func respondToSwipeGesture(_ gesture : UIGestureRecognizer) { if let swipeGesture = gesture as? UISwipeGestureRecognizer { switch swipeGesture.direction { case .right: print("swiped right!") case .left: print("Swiped left") case .up: print("Swiped up") case .down: print("Swiped down") default: return } } } lazy var rightSwipe: UISwipeGestureRecognizer = { let rightSwipeGR = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture(_:))) rightSwipeGR.direction = .right return rightSwipeGR }() lazy var leftSwipe: UISwipeGestureRecognizer = { let leftSwipeGR = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture(_:))) leftSwipeGR.direction = .left return leftSwipeGR }() } You can use self in the initial values of lazy instance property. To run some executable statement like rightSwipe.direction = .right, you need to create a function and call it. If you do want to call the method respondToSwipeGesture(_:) of GestureManager, the target needs to be self, not self.vc. If you are not accustomed to utilizing closure, you can define explicit functions: lazy var rightSwipe: UISwipeGestureRecognizer = createRightSwipeGR() private func createRightSwipeGR() - UISwipeGestureRecognizer { let rightSwipeGR = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture(_:))) rightSwipeGR.direction = .right return rightSwipeGR } lazy var leftSwipe: UISwipeGestureRecognizer = createLeftSwipeGR() private func createLeftSwipeGR() - UISwipeGestureRecognizer { let leftSwipeGR = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture(_:))) leftSwipeGR.direction = .left return leftSwipeGR }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21