2015年の目標は、iPhoneアプリを毎月一本作る!ということで
1月分としてSwiftでアプリを作ります。(すでに2月ですが、、、)

Swiftで○×ゲームを作る

swiftgame

//
// GameViewController.swift
// SwiftGame
//
import UIKit
import SpriteKit</code>

extension SKNode {
class func unarchiveFromFile(file : NSString) -&gt; SKNode? {
if let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks") {
var sceneData = NSData(contentsOfFile: path, options: .DataReadingMappedIfSafe, error: nil)!
var archiver = NSKeyedUnarchiver(forReadingWithData: sceneData)

archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as GameScene
archiver.finishDecoding()
return scene
} else {
return nil
}
}
}

class GameViewController: UIViewController , UIGestureRecognizerDelegate{
var scene: GameScene!

override func viewDidLoad() {
super.viewDidLoad()
let skView = view as SKView
skView.multipleTouchEnabled = false

scene = GameScene(size: skView.bounds.size)
scene.scaleMode = .AspectFill
skView.presentScene(scene)
}

override func prefersStatusBarHidden() -&gt; Bool {
return true
}

@IBAction func didTap(sender: UITapGestureRecognizer) {
let location = sender.locationInView(view)
println("tapped at \(location.x), \(location.y)")
scene.mark(location)
}
}
//
// GameScene.swift
// SwiftGame
//
import SpriteKit</code>

class GameScene: SKScene {
var turn_o = true

required init(coder aDecoder: NSCoder!) {
fatalError("NSCoder not supported")
}

override init(size: CGSize) {
super.init(size: size)

anchorPoint = CGPoint(x: 0, y: 0)

let background = SKSpriteNode(imageNamed: "bg")
background.position = CGPoint(x: 0, y: 0)
background.anchorPoint = CGPoint(x: 0, y: 0)
addChild(background)
}

override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}

func transform(w: CGFloat) -&gt; CGFloat {
switch w {
case let w where 0 &lt; w &amp;&amp; w &lt; 80:
return 0
case let w where 80 &lt; w &amp;&amp; w &lt; 160:
return 80
case let w where 160 &lt; w &amp;&amp; w &lt; 240:
return 160
default:
return -80
}
}

func mark(location: CGPoint) {
let imageName = turn_o ? "o" : "x"
let sign = SKSpriteNode(imageNamed: imageName)
sign.position = CGPoint(x: transform(location.x), y: 160 - transform(location.y - 320))
sign.anchorPoint = CGPoint(x: 0, y: 0)
addChild(sign)

turn_o = !turn_o
}
}
//
// AppDelegate.swift
// SwiftGame
//</code>

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -&gt; Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

}

参考
Swift日本語チュートリアル ~ 前編(Apple公式ドキュメントSwift Tour±α) – こんにゃくマガジン http://xavier.hateblo.jp/entry……/12/223346

Swift日本語チュートリアル ~ 後編(Apple公式ドキュメントSwift Tour±α) – こんにゃくマガジン
http://xavier.hateblo.jp/entry……/14/201418

Swiftで初めてiPhoneゲーム開発する人向チュートリアル(マルバツゲームを例にStep by Step解説) – こんにゃくマガジン
http://xavier.hateblo.jp/entry……/07/144059

[iOS][Mac] Swift を学べる記事のまとめ|クラスメソッドブログ http://dev.classmethod.jp/smar……arn-swift/

新しいプログラミング言語 Swift|クラスメソッドブログ
http://dev.classmethod.jp/smar……one/swift/

逆引きSwift
https://sites.google.com/a/gcl……wift-docs/