Post

Replies

Boosts

Views

Activity

Why doesn't Xcode's "Download Container" not always work?
Been using Xcode's Download Container for a short time, and at first there were no issues. But lately, it doesn't always download all the files from my iPhone to the Mac. Sometimes cleaning the build folder works, other times not. As well, the same happens whether I am connected to my iPhone via cable, or wifi. Has anyone else had this issue?
6
0
446
Nov ’24
Is there a global Alert View in SwiftUI?
I am writing a SwiftUI based app, and errors can occur anywhere. I've got a function that logs the error. But it would be nice to be able to call an Alert Msg, no matter where I am, then gracefully exits the app. Sure I can right the alert into every view, but that seems ridiculously unnecessary. Am I missing something?
2
0
174
Apr ’25
Need help on SQLite wrapper for Swift
I am using the SQLite wrapper for Xcode. I got it from the link below and did install it. But was hoping there would better documentation, or tutorials out there for it. Am new enough at Swift and its syntax. Whatever can make this easier for me would be a big help. https: //git.pado.name/reviewspur/ios/tree/fd2486cf91e422e2df8d048ffd2d40ea89527685/Carthage/Checkouts/SQLite.swift/Documentation#building-type-safe-sql
0
0
419
May ’21
What is the syntax for "if not" in Swift?
I have the code below which works just fine. getTwinklingGem returns type MyGem. What I cannot figure out is if there is a proper syntax for writing the NOT into the if statement. Am still too new to Swift. This works, but seems lengthy: if let twinkling = getHighGem(), twinkling != nil Is this the proper way to test for a nil return? if let twinkling = getHighGem() as? MyGem if let twinkling = getTwinklingGem() { print ("not nil") }
4
0
2.5k
Jun ’21
How to refine the shape of an SKSpriteNode for tap gestures?
In my app I create mutiple SKSpriteNodes, gems. Code snippet 1 When I loop through nodes from the main scene in a tap gesture, Code snippet 2, the gems register in a perfect square shape even though they are not. I have highlighted all areas that the orange gem registers in a tap as white. Here is the screen shot http://98.7.37.117/gem.png Since the gem is itself not a square, I'd like to know if there is a way refine its shape so it would only show up in the list of nodes in UITapGestureRecognizer if the orange part is tapped. I have even tried by assigning it a physicsBody. But that made no difference. Code Snippet 1 class MyGem : SKSpriteNode{ init(iColor : Gems) { fileName = "\(iColor)_gem" let skTexture = SKTexture(imageNamed: fileName) super.init(texture: skTexture, color: .clear, size: .zero) self.isHidden = true self.anchorPoint = CGPoint(x: 0.5, y: 0.5) self.size = CGSize(width: myGV.gemSize.width, height: myGV.gemSize.height) self.zPosition = theZ.gem self.position = CGPoint(x: 0, y: 0 ) self.isUserInteractionEnabled = false self.name = "gem" } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } } Code Snippet 2 @objc func tappedView(_ sender:UITapGestureRecognizer) { if sender.state == .ended{ var post = sender.location(in: sender.view) post = self.convertPoint(fromView: post) for node in self.nodes(at: post){ if let touchNode = node as? MyGem print("touched gem") highliteGem(theGem: touchNode, clearAll: false) return }
6
0
957
Jul ’21
What happens if I execute an SKAction run sequence on a node that is already executing another sequence?
I have an SKSpriteNode with an SKAction being run on it: theGem!.run(premAction, completion: {theGem!.run(repeatAction)}) Can't seem to find out the proper steps to run another action, such as: theGem.run(endsequence, completion: {theGem.removeAllActions(); theGem.run(stopAction)}) Should I stop the previous action first? Is there a way to turn the repeat part off so that the first SKAction ends smoothly?
0
0
497
Aug ’21
How to keep two SKPhysicsBodyies from passing through each other?
In my app, I have greyBars and one border bar. The border bar keeps the greyBars from falling off the screen. Only one greyBar is used at a time. When it is completely filed with colored gems, a new bar is created and brought up from the bottom of the screen, with the code below. The result I want is that the new bar, the one with all white diamonds pushes up the old bar and the new bar remains on the bottom. You can see by the screenshot that somehow the new bar ended up on top, even though it was coming from the bottom. I slowed down the duration of the greyBar's movement to see what was going wrong. While the two greyBars do clash with each other, the new one (the one on the bottom) ends up pushing THROUGH the top bar. My assumption was that the new greyBar would just push up the old bar(s), and remain on the bottom. Is there some "solidity" type property that I am missing? myGreyBar[0].physicsBody?.categoryBitMask = bodyMasks.greyBarMask.rawValue myGreyBar[0].physicsBody?.contactTestBitMask = bodyMasks.blankMask.rawValue myGreyBar[0].physicsBody?.collisionBitMask = bodyMasks.greyBarMask.rawValue myGreyBar[0].isHidden = false; myGV.gameScene?.addChild(myGreyBar[0]) let moveAction = SKAction.move(to: CGPoint(x:(myGV.safeSceneRect.width/2) - (size.width/2), y: (myGemBase?.size.height)! + (myGV.border?.size.height)! + 200), duration: 10.0) myGreyBar[0].run(moveAction, completion:{myGreyBar[0].physicsBody?.collisionBitMask = bodyMasks.borderMask.rawValue|bodyMasks.greyBarMask.rawValue})
0
0
448
Sep ’21
What is the proper term for create a world in Swift?
I know it's uncool to ask vague questions here, but what do they call it when you create a world and follow it with a camera in Swift? Like an RPG? Like Doom? I want to try and learn that now. And more importantly can it be done without using the Xcode scene builder? Can it be done all via code? Thanks, as always. Without the forum I would never have gotten much farther than "Hello World!"
1
0
650
Sep ’21
How can I change the bounce of SKSpriteNode dynamically?
I have a very simple app. All SKSpriteNodes, myBall, myBlue, and myRed. Only myBall moves, affected by gravity, and bounces off of different objects (myRed and myBlue). What I can't figure out is how to make myBall bounce harder or softer depending on which body it hits? I hav been playing with the density of all the objects, but it doesn't seem to make any difference? Is there some property I am unaware of? Or are there other methods?
0
0
402
Oct ’21
How can I apply safeAreaLayouts to multiple views?
When my app starts up I have my ViewController, which automatically creates my MainScreen (also a view controller). Right after self.addChild(mainController) I call a function which sets my constraints func setConstraints (vc: UIViewController) { vc.view.translatesAutoresizingMaskIntoConstraints = false var constraints = [NSLayoutConstraint]() constraints.append(vc.view.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor)) constraints.append(vc.view.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor)) constraints.append(vc.view.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)) constraints.append(vc.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)) NSLayoutConstraint.activate(constraints) } All is fine up to this point, the MainScreen is bound by the top and bottom safe areas. At some point from MainScreen I create another UIViewController. countController.modalPresentationStyle = .fullScreen self.present(countController, animated: true, completion: {}) Yet, no matter how hard I try to apply the constraints to the new controller, I crash with the following msg: Unable to activate constraint with anchors <NSLayoutXAxisAnchor....because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal." Am too new to figure out where my error is.
0
0
395
Nov ’21
Why does a dismissed child UIView doesn't reappear properly after its first appearance?
Thanks to people on this board I am able to successfully calla up a child UIViewConroller via animation with: This is the buttonAction from the Main UIViewController, which calls up setController @objc func buttonAction(sender: UIButton!) { guard let theButton = sender as? MyButton else { return} UIView.transition(with: self.view, duration: 0.5, options: .transitionCurlDown, animations: { [self] in self.addChild(setController); self.view.addSubview(setController.view); }, completion: { [self]_ in setController.didMove(toParent: self); setController.doLayout();}) } the doLayout method lies within the child: func doLayout (){ guard let parent = cView!.view.superview else {return} //make sure UIV honors safeAreaLayouts setConstraints(vc: self, pc: parent) } A button within the child, setController, dismisses itself: @objc func buttonAction(sender: UIButton!) { self.willMove(toParent: nil) self.removeFromParent() self.view.removeFromSuperview() self.dismiss(animated: false, completion: nil) } Everything works great the first time I call up the child UIView. It curls down while covering the first/parent UIVIEW, etc. etc. Figure 1 But after I dismiss the child view and call it again, the child view scrolls down without really covering the main view, it's like a mishmash. Figure 2 Only after all is said and done, then the child view covers everything. So am curious if I am dismissing something incorrectly.
3
0
805
Dec ’21
Why doesn't Xcode's "Download Container" not always work?
Been using Xcode's Download Container for a short time, and at first there were no issues. But lately, it doesn't always download all the files from my iPhone to the Mac. Sometimes cleaning the build folder works, other times not. As well, the same happens whether I am connected to my iPhone via cable, or wifi. Has anyone else had this issue?
Replies
6
Boosts
0
Views
446
Activity
Nov ’24
Is there a global Alert View in SwiftUI?
I am writing a SwiftUI based app, and errors can occur anywhere. I've got a function that logs the error. But it would be nice to be able to call an Alert Msg, no matter where I am, then gracefully exits the app. Sure I can right the alert into every view, but that seems ridiculously unnecessary. Am I missing something?
Replies
2
Boosts
0
Views
174
Activity
Apr ’25
Need help on SQLite wrapper for Swift
I am using the SQLite wrapper for Xcode. I got it from the link below and did install it. But was hoping there would better documentation, or tutorials out there for it. Am new enough at Swift and its syntax. Whatever can make this easier for me would be a big help. https: //git.pado.name/reviewspur/ios/tree/fd2486cf91e422e2df8d048ffd2d40ea89527685/Carthage/Checkouts/SQLite.swift/Documentation#building-type-safe-sql
Replies
0
Boosts
0
Views
419
Activity
May ’21
Is it ok to have each SKSPriteNode's isUserInteractionEnabled set to true?
Am making a game which will have 6 interactive SKSpriteNodes. Is there anything wrong with having each node handle its own user interactions? Or is better to have all user touch interactions handled through one scene (GameScene)? Or is there, perhaps, no difference?
Replies
0
Boosts
0
Views
451
Activity
May ’21
Is there a method that returns how much space is being occupied by two sprites at the same time?
I am working on my first game, and I do know about collision detecting. I am curious if there is a method that returns how much space is being occupied by two sprites at the same time? Am sure there are multiple reasons to calculate this, but in my case one sprite can be touching at least 2 other sprites at once.
Replies
1
Boosts
0
Views
520
Activity
May ’21
What is the syntax for "if not" in Swift?
I have the code below which works just fine. getTwinklingGem returns type MyGem. What I cannot figure out is if there is a proper syntax for writing the NOT into the if statement. Am still too new to Swift. This works, but seems lengthy: if let twinkling = getHighGem(), twinkling != nil Is this the proper way to test for a nil return? if let twinkling = getHighGem() as? MyGem if let twinkling = getTwinklingGem() { print ("not nil") }
Replies
4
Boosts
0
Views
2.5k
Activity
Jun ’21
How to refine the shape of an SKSpriteNode for tap gestures?
In my app I create mutiple SKSpriteNodes, gems. Code snippet 1 When I loop through nodes from the main scene in a tap gesture, Code snippet 2, the gems register in a perfect square shape even though they are not. I have highlighted all areas that the orange gem registers in a tap as white. Here is the screen shot http://98.7.37.117/gem.png Since the gem is itself not a square, I'd like to know if there is a way refine its shape so it would only show up in the list of nodes in UITapGestureRecognizer if the orange part is tapped. I have even tried by assigning it a physicsBody. But that made no difference. Code Snippet 1 class MyGem : SKSpriteNode{ init(iColor : Gems) { fileName = "\(iColor)_gem" let skTexture = SKTexture(imageNamed: fileName) super.init(texture: skTexture, color: .clear, size: .zero) self.isHidden = true self.anchorPoint = CGPoint(x: 0.5, y: 0.5) self.size = CGSize(width: myGV.gemSize.width, height: myGV.gemSize.height) self.zPosition = theZ.gem self.position = CGPoint(x: 0, y: 0 ) self.isUserInteractionEnabled = false self.name = "gem" } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } } Code Snippet 2 @objc func tappedView(_ sender:UITapGestureRecognizer) { if sender.state == .ended{ var post = sender.location(in: sender.view) post = self.convertPoint(fromView: post) for node in self.nodes(at: post){ if let touchNode = node as? MyGem print("touched gem") highliteGem(theGem: touchNode, clearAll: false) return }
Replies
6
Boosts
0
Views
957
Activity
Jul ’21
Why do I get touchesCanceled all the time?
Just curious why I get touchesCanceled even after I process: @objc func tappedView(_ sender:UITapGestureRecognizer) It's requiring a lot of extra coding to determine a real cancel vs I just got a tap.
Replies
2
Boosts
0
Views
456
Activity
Aug ’21
Can i turn a touchesCancelled onto touchesEnded?
I handled everything through touchesEnded. Was curious if I could hand off the call to touchesEnded from touchesCancelled?
Replies
2
Boosts
0
Views
457
Activity
Aug ’21
What happens if I execute an SKAction run sequence on a node that is already executing another sequence?
I have an SKSpriteNode with an SKAction being run on it: theGem!.run(premAction, completion: {theGem!.run(repeatAction)}) Can't seem to find out the proper steps to run another action, such as: theGem.run(endsequence, completion: {theGem.removeAllActions(); theGem.run(stopAction)}) Should I stop the previous action first? Is there a way to turn the repeat part off so that the first SKAction ends smoothly?
Replies
0
Boosts
0
Views
497
Activity
Aug ’21
How to keep two SKPhysicsBodyies from passing through each other?
In my app, I have greyBars and one border bar. The border bar keeps the greyBars from falling off the screen. Only one greyBar is used at a time. When it is completely filed with colored gems, a new bar is created and brought up from the bottom of the screen, with the code below. The result I want is that the new bar, the one with all white diamonds pushes up the old bar and the new bar remains on the bottom. You can see by the screenshot that somehow the new bar ended up on top, even though it was coming from the bottom. I slowed down the duration of the greyBar's movement to see what was going wrong. While the two greyBars do clash with each other, the new one (the one on the bottom) ends up pushing THROUGH the top bar. My assumption was that the new greyBar would just push up the old bar(s), and remain on the bottom. Is there some "solidity" type property that I am missing? myGreyBar[0].physicsBody?.categoryBitMask = bodyMasks.greyBarMask.rawValue myGreyBar[0].physicsBody?.contactTestBitMask = bodyMasks.blankMask.rawValue myGreyBar[0].physicsBody?.collisionBitMask = bodyMasks.greyBarMask.rawValue myGreyBar[0].isHidden = false; myGV.gameScene?.addChild(myGreyBar[0]) let moveAction = SKAction.move(to: CGPoint(x:(myGV.safeSceneRect.width/2) - (size.width/2), y: (myGemBase?.size.height)! + (myGV.border?.size.height)! + 200), duration: 10.0) myGreyBar[0].run(moveAction, completion:{myGreyBar[0].physicsBody?.collisionBitMask = bodyMasks.borderMask.rawValue|bodyMasks.greyBarMask.rawValue})
Replies
0
Boosts
0
Views
448
Activity
Sep ’21
What is the proper term for create a world in Swift?
I know it's uncool to ask vague questions here, but what do they call it when you create a world and follow it with a camera in Swift? Like an RPG? Like Doom? I want to try and learn that now. And more importantly can it be done without using the Xcode scene builder? Can it be done all via code? Thanks, as always. Without the forum I would never have gotten much farther than "Hello World!"
Replies
1
Boosts
0
Views
650
Activity
Sep ’21
How can I change the bounce of SKSpriteNode dynamically?
I have a very simple app. All SKSpriteNodes, myBall, myBlue, and myRed. Only myBall moves, affected by gravity, and bounces off of different objects (myRed and myBlue). What I can't figure out is how to make myBall bounce harder or softer depending on which body it hits? I hav been playing with the density of all the objects, but it doesn't seem to make any difference? Is there some property I am unaware of? Or are there other methods?
Replies
0
Boosts
0
Views
402
Activity
Oct ’21
How can I apply safeAreaLayouts to multiple views?
When my app starts up I have my ViewController, which automatically creates my MainScreen (also a view controller). Right after self.addChild(mainController) I call a function which sets my constraints func setConstraints (vc: UIViewController) { vc.view.translatesAutoresizingMaskIntoConstraints = false var constraints = [NSLayoutConstraint]() constraints.append(vc.view.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor)) constraints.append(vc.view.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor)) constraints.append(vc.view.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)) constraints.append(vc.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)) NSLayoutConstraint.activate(constraints) } All is fine up to this point, the MainScreen is bound by the top and bottom safe areas. At some point from MainScreen I create another UIViewController. countController.modalPresentationStyle = .fullScreen self.present(countController, animated: true, completion: {}) Yet, no matter how hard I try to apply the constraints to the new controller, I crash with the following msg: Unable to activate constraint with anchors <NSLayoutXAxisAnchor....because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal." Am too new to figure out where my error is.
Replies
0
Boosts
0
Views
395
Activity
Nov ’21
Why does a dismissed child UIView doesn't reappear properly after its first appearance?
Thanks to people on this board I am able to successfully calla up a child UIViewConroller via animation with: This is the buttonAction from the Main UIViewController, which calls up setController @objc func buttonAction(sender: UIButton!) { guard let theButton = sender as? MyButton else { return} UIView.transition(with: self.view, duration: 0.5, options: .transitionCurlDown, animations: { [self] in self.addChild(setController); self.view.addSubview(setController.view); }, completion: { [self]_ in setController.didMove(toParent: self); setController.doLayout();}) } the doLayout method lies within the child: func doLayout (){ guard let parent = cView!.view.superview else {return} //make sure UIV honors safeAreaLayouts setConstraints(vc: self, pc: parent) } A button within the child, setController, dismisses itself: @objc func buttonAction(sender: UIButton!) { self.willMove(toParent: nil) self.removeFromParent() self.view.removeFromSuperview() self.dismiss(animated: false, completion: nil) } Everything works great the first time I call up the child UIView. It curls down while covering the first/parent UIVIEW, etc. etc. Figure 1 But after I dismiss the child view and call it again, the child view scrolls down without really covering the main view, it's like a mishmash. Figure 2 Only after all is said and done, then the child view covers everything. So am curious if I am dismissing something incorrectly.
Replies
3
Boosts
0
Views
805
Activity
Dec ’21