LoginSignup
10
10

More than 5 years have passed since last update.

Swiftを勉強しようとしたらFlappy Birdのデモコードが動かなくて詰んだ話

Posted at

使用環境 : Xcode6.1(6A1052d) / OS X Yosemite 10.10
※ 注意 筆者はSwiftを勉強し始めてから1時間しか経っていないので詳しいことは分かりません
とりあえず動くようにするための方法を記録として残しておきます。

Swiftを勉強しようとしてSwiftクローン版のFlappyBirdを落とした

→ これ(https://github.com/fullstackio/FlappySwift)

コンパイルした

スクリーンショット 2014-11-03 19.07.52.png
なんかめっさエラー出た。

エラーの詳細とその対処

'dataWithContentsOfFile(_:options:error:)' is unavailable: use object construction 'NSData(contentsOfFile:options:error:)'

dataWithContentsOfFileのerrorオプションはコンストラクタで使えないとか言ってる?
Swiftの仕様変更だと思うのですが、当方1時間しか勉強していないので誰か教えて下さい。
このエラーは以下の行で出力されるので、

GameViewController.swift
let sceneData = NSData.dataWithContentsOfFile(path!, options: .DataReadingMappedIfSafe, error: nil)

こう直す。

GameViewController.swift
var sceneData = NSData(contentsOfFile: path!, options: .DataReadingMappedIfSafe, error: nil)!

下の方には同じエラーが2箇所出ています。

Method 'fromRaw' has been replaced with a property 'rawValue'

これは以下の行で出ているので、

GameViewController.swift
return Int(UIInterfaceOrientationMask.AllButUpsideDown.toRaw())

toRaw()をrawValueに置き換えてやる

GameViewController.swift
return Int(UIInterfaceOrientationMask.AllButUpsideDown.rawValue)

こちらについてはQiitaで解説を見つけられました。
Xcode6.1 Beta2での変更らしいです。
http://qiita.com/dankogai/items/fe86f43a0158c13082ad

参考にしたサイト

THE LAST DAY (http://ngw.jp/~tato/wp/?tag=swift)

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10