Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sebastijan

macrumors member
Original poster
I'm pretty new to Swift and I'm having some trouble implementing alerts into my SpriteKit game. The below code works on device & emulator, however every time I run the code I get two warnings.

GameViewController.swift:
Swift:
import SpriteKit

class GameViewController: UIViewController {

override func viewDidLoad() {
   
    let scene = SceneMenu(size: view.frame.size)
    scene.scaleMode = .aspectFill
    scene.backgroundColor = .white
   
    let view = view as! SKView
    view.presentScene(scene)
   
}

}

SceneMenu.swift:
Swift:
import SpriteKit

class SceneMenu: SKScene {

override init(size: CGSize) {
   
    super.init(size: size)
   
    let btnAlert = SKLabelNode(text: "Show Alert")
    btnAlert.name = "btn_alert"
    btnAlert.fontSize = 20
    btnAlert.fontColor = SKColor.blue
    btnAlert.fontName = "Avenir"
    btnAlert.position = CGPoint(x: size.width / 2, y: size.height / 2)
    addChild(btnAlert)
   
}

required init?(coder aDecoder: NSCoder) {
   
    fatalError("init(coder:) has not been implemented")
   
}

func showAlert() {
   
    let alert = UIAlertController(title: "title", message: "message", preferredStyle: UIAlertController.Style.alert)
   
    alert.addTextField { field in
        field.placeholder = "Type your name"
    }
   
    alert.addAction(UIAlertAction(title: "OK", style: .default) { _ in
        print("OK")
    })
   
    view?.window?.rootViewController?.present(alert, animated: true)
   
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
   
    if let touch = touches.first {
       
        let location = touch.location(in: self)
        let action = atPoint(location)
       
        if action.name == "btn_alert" {
           
            showAlert()
           
        }
       
    }
   
}

}

Debug warning #1:
2022-06-04 15:31:46.134563+0100 Game16[86767:3617120] [LayoutConstraints] Changing the translatesAutoresizingMaskIntoConstraints property of a UICollectionViewCell that is managed by a UICollectionView is not supported, and will result in incorrect self-sizing. View: <_UIAlertControllerTextFieldViewCollectionCell: 0x122022da0; frame = (0 0; 270 24); gestureRecognizers = <NSArray: 0x600000a97e40>; layer = <CALayer: 0x600000498220>>

Debug warning #2:
2022-06-04 15:32:10.228624+0100 Game16[86767:3617120] [HardwareKeyboard] -[UIApplication getKeyboardDevicePropertiesForSenderID:shouldUpdate:usingSyntheticEvent:], failed to fetch device property for senderID (778835616971358211) use primary keyboard info instead.

Any help would be appreciated. thanks.
 
After further testing, I noticed that debug warning #1 is displayed on both device and in emulator <- that's the only issue now.

While debug warning #2 is displayed only in emulator which can be resolved by disabling "Connect Hardware Keyboard".


d8f8588b-4bf2-4bac-8686-154836b8ba75.png
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.