I'm baffled. I did C++ and Java. More on the Java side. Both languages's main entry of execution is the main method. But I do not see a main method in Swift.
I'm learning Game Programming using the Swift and I did some println statements just to see which one runs first.
import UIKit
import SpriteKit
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let scene = GameScene(size: view.bounds.size)
let skView = view as SKView
skView.showsFPS = true
skView.showsNodeCount = true
skView.ignoresSiblingOrder = true
scene.scaleMode = .ResizeFill
skView.presentScene(scene)
println("c")
}
override func prefersStatusBarHidden() -> Bool {
println("a")
return true
}
}
import SpriteKit
class GameScene: SKScene {
// 1
let player = SKSpriteNode(imageNamed: "player")
override func didMoveToView(view: SKView) {
// 2
backgroundColor = SKColor.whiteColor()
// 3
player.position = CGPoint(x: size.width * 0.1, y: size.height * 0.5)
// 4
addChild(player)
println("b")
}
}
Consoleoutput:
a
b
c
a
a
Based on the console output:
1) the override function prefersStatusBarHidden() in GameViewController.swift runs first
2) the override function didMoveToView in GameScene.swift runs second
3) the override function viewDidLoad in GameViewController.swift runs third
4) The fourth step consisting of step #1 running twice (based on the console output)
Is the main entry of execution in Swift actually what I pointed out above? Seems to be a break away from convention or tradition of executing a program.