Post

Replies

Boosts

Views

Activity

Reply to Spawn Enemy Code Not working
Not working is not precise enough. Does it compile (I guess no) What do you get ? What did you expect ? . Have you check that spawnEnemy is even called ? have you checked positions are correct ? Do you need randomXEnd to be larger than randomXStart ? So add a few print and correct errors on how you use of random: func spawnEnemy(){ print("Start spawn") // <-- Add this // Replace this --> let randomXStart = random(min: gameArea.minX, max: gameArea.maxX) let randomXStart = (gameArea.minX...gameArea.maxX).randomElement() ?? gameArea.minX // Replace this --> let randomXEnd = random(min: gameArea.minX, max: gameArea.maxX) let randomXEnd = (gameArea.minX...gameArea.maxX).randomElement() ?? gameArea.maxX // If you need randomXEnd to be larger than randomXStart, replace line above with // let randomXEnd = (randomXStart...gameArea.maxX).randomElement() ?? gameArea.maxX let startPoint = CGPoint(x: randomXStart, y: self.size.height * 1.2) let endPoint = CGPoint(x: randomXEnd, y: -self.size.height * 0.2) print("startPoint", startPoint, "endPoint", endPoint) let enemy = SKSpriteNode(imageNamed: "enemyShip") enemy.setScale(1) enemy.position = startPoint enemy.zPosition = 2 self.addChild(enemy) let moveEnemy = SKAction.move(to: endPoint, duration: 1.5) let deleteEnemy = SKAction.removeFromParent() let enemySequence = SKAction.sequence([moveEnemy, deleteEnemy]) enemy.run(enemySequence) let dx = endPoint.x - startPoint.x let dy = endPoint.y - startPoint.y let amountToRotate = atan2(dy,dx) print("dx", dx, "dy", dy, "rotation", amountToRotate) // <-- Add this enemy.zRotation = amountToRotate } You should also check amountToRotate what happens if dy = 0 is it in the right order of parameters ? If dx = 0 do you want zero rotation ? Test and report what you get. If it does not work as expected, please explain ; otherwise, don't forget to close the thread on the correct answer. Good luck.
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to Why does Apple not mark solved bugs as solved?
That would be nice indeed. But that would require to go back and check that the solved bug corresponds exactly to the bug report. With the number of bugs they get, such a tracking would be heavy task. So it is up to us (the bug reporter) to check if new release has solved the issue. They sometime mention the bug n° in the Release notes. You could file a bug report for enhancement suggestion. And then track it of course…😊
Nov ’21
Reply to How to simulate mouse/finger click on iOS?
Is it possible to trigger finger/mouse click in iOS app? Don't think it is possible to create the event directly. See this very old thread: https://www.cocoawithlove.com/2008/10/synthesizing-touch-event-on-iphone.html But you could try to: find which object it at some coordinates get the topmost (first to respond) trigger the action: IBAction for a button for instance is possible to call clicks from my app working in background to make some clicks in other apps/launcher? I don't think neither, that would create a risk that an app does bad things on the iPhone
Nov ’21
Reply to Compile for different macOS versions
Yes there is. You have @available for a func: @available(macOS 11.0, *) func … and for a piece of code: if #available(macOS 11, *) { print("This code only runs on macOS 11 and up") } else { print("This code only runs on macOS 10 and lower") } get much details here for instance: h t t p s : / / w w w.avanderlee.com/swift/available-deprecated-renamed/
Nov ’21
Reply to function writeFile()
You should format code with formatter (<>) to make it readable: And put statements to see what's going on: func writeFile() { let file = "blw.txt" let text = "hakemisto" let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! print("documentDir: (documentDirectory)", FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first) // <<-- To check if not nil if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first { let fileURL = dir.appendingPathComponent(file) do { try text.write(to: fileURL, atomically: false, encoding: .utf8) } catch {              print("Failed to write text: \(error.localizedDescription)") } } } You may have a sandbox issue. You need to use NSSavePanel() to access the file.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’21
Reply to Spawn Enemy Code Not working
Not working is not precise enough. Does it compile (I guess no) What do you get ? What did you expect ? . Have you check that spawnEnemy is even called ? have you checked positions are correct ? Do you need randomXEnd to be larger than randomXStart ? So add a few print and correct errors on how you use of random: func spawnEnemy(){ print("Start spawn") // <-- Add this // Replace this --> let randomXStart = random(min: gameArea.minX, max: gameArea.maxX) let randomXStart = (gameArea.minX...gameArea.maxX).randomElement() ?? gameArea.minX // Replace this --> let randomXEnd = random(min: gameArea.minX, max: gameArea.maxX) let randomXEnd = (gameArea.minX...gameArea.maxX).randomElement() ?? gameArea.maxX // If you need randomXEnd to be larger than randomXStart, replace line above with // let randomXEnd = (randomXStart...gameArea.maxX).randomElement() ?? gameArea.maxX let startPoint = CGPoint(x: randomXStart, y: self.size.height * 1.2) let endPoint = CGPoint(x: randomXEnd, y: -self.size.height * 0.2) print("startPoint", startPoint, "endPoint", endPoint) let enemy = SKSpriteNode(imageNamed: "enemyShip") enemy.setScale(1) enemy.position = startPoint enemy.zPosition = 2 self.addChild(enemy) let moveEnemy = SKAction.move(to: endPoint, duration: 1.5) let deleteEnemy = SKAction.removeFromParent() let enemySequence = SKAction.sequence([moveEnemy, deleteEnemy]) enemy.run(enemySequence) let dx = endPoint.x - startPoint.x let dy = endPoint.y - startPoint.y let amountToRotate = atan2(dy,dx) print("dx", dx, "dy", dy, "rotation", amountToRotate) // <-- Add this enemy.zRotation = amountToRotate } You should also check amountToRotate what happens if dy = 0 is it in the right order of parameters ? If dx = 0 do you want zero rotation ? Test and report what you get. If it does not work as expected, please explain ; otherwise, don't forget to close the thread on the correct answer. Good luck.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Is it possible to draw line from view to another view
You just have to draw in the superview of both views. Very easy in UIKit, did not try in SwiftUI.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to How to see sales figure by cities
AFAIK, answer is no. The lowest level is the country (that's the level you have defined for sales in countries).
Replies
Boosts
Views
Activity
Nov ’21
Reply to Why does Apple not mark solved bugs as solved?
That would be nice indeed. But that would require to go back and check that the solved bug corresponds exactly to the bug report. With the number of bugs they get, such a tracking would be heavy task. So it is up to us (the bug reporter) to check if new release has solved the issue. They sometime mention the bug n° in the Release notes. You could file a bug report for enhancement suggestion. And then track it of course…😊
Replies
Boosts
Views
Activity
Nov ’21
Reply to Low performance on matrix multiplication
Can you look into this issue? Did you post a bug report ? Or you could also burn a DTS ticket.
Topic: Graphics & Games SubTopic: General Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Can my app be found in another country(localization) with an existing name
Maybe I miss something, but you should not be authorised to use an existing name. And the other company may request Apple to withdraw your app from the Appstore. But in such a case, both apps would appear in a search. That occurs if you have an existing app "AnApp" and you call yours "AnApp2".
Replies
Boosts
Views
Activity
Nov ’21
Reply to How to simulate mouse/finger click on iOS?
Is it possible to trigger finger/mouse click in iOS app? Don't think it is possible to create the event directly. See this very old thread: https://www.cocoawithlove.com/2008/10/synthesizing-touch-event-on-iphone.html But you could try to: find which object it at some coordinates get the topmost (first to respond) trigger the action: IBAction for a button for instance is possible to call clicks from my app working in background to make some clicks in other apps/launcher? I don't think neither, that would create a risk that an app does bad things on the iPhone
Replies
Boosts
Views
Activity
Nov ’21
Reply to Does unifiedContacts(matching:keysToFetch:) return only unified contacts and leave out non-unified contacts?
Doc for unifiedContacts(matching:keysToFetch:)says: Fetches all unified contacts matching the specified predicate. So I understand that non-unified contacts are not fetched.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Compile for different macOS versions
Yes there is. You have @available for a func: @available(macOS 11.0, *) func … and for a piece of code: if #available(macOS 11, *) { print("This code only runs on macOS 11 and up") } else { print("This code only runs on macOS 10 and lower") } get much details here for instance: h t t p s : / / w w w.avanderlee.com/swift/available-deprecated-renamed/
Replies
Boosts
Views
Activity
Nov ’21
Reply to Are you interested in a opportunity ?
Please note that this forum is not made for this type of soliciting.
Replies
Boosts
Views
Activity
Nov ’21
Reply to function writeFile()
You should format code with formatter (<>) to make it readable: And put statements to see what's going on: func writeFile() { let file = "blw.txt" let text = "hakemisto" let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! print("documentDir: (documentDirectory)", FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first) // <<-- To check if not nil if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first { let fileURL = dir.appendingPathComponent(file) do { try text.write(to: fileURL, atomically: false, encoding: .utf8) } catch {              print("Failed to write text: \(error.localizedDescription)") } } } You may have a sandbox issue. You need to use NSSavePanel() to access the file.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Mouse not connecting
none of my mice will connect Which mice models are they ? . I tried connecting with a cable to my track ball Did you try to connect directly to the Mac ?
Topic: App & System Services SubTopic: Hardware Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Triangle Intersection in 3D Space
If someone finds some wrong math or wrong results please let me know. ¡¿¡¿ You should be the one to tell if that works !?!? Not very fair you didn't even test or feedback to the code I wrote for your question…
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Reference to member 'delegate' cannot be resolved without a contextual type
Previous post plus: This code is bizarre: 1. override func viewDidLoad() { 2. super.viewDidLoad() 3. fetchJSON { 4. print("APICompleted") 5. 6. } 7. tableView.delegate = self //error// 8. tableView.dataSource = self //error// 9. } Line 6 (closing curly brace) should not be.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to How to store one line of code from class into a button action?
Is it the complete code for the class or is there some code after ? Otherwise there misses }) a closing curly bracket and parenthesis at least. Could you post the SocketManager class definition ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’21