Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/users/1/juny/web/hidef/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

Swiftの覚書1

公開日: : 最終更新日:2014/08/09 iPhone App 開発, Swift ,


Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/users/1/juny/web/hidef/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

Swift

先日、Appleから新言語Swiftが発表されました。

apple-swift-language1

今までiOSアプリで開発していたObjective-Cから移行しそうな勢いなので、XcodeのBeta版をインストールして勉強しています。

 

Xcode Beta版やiOS8ダウンロードはこちらのページから。

https://developer.apple.com/devcenter/ios/index.action

 

Swiftに関するドキュメントはiBooksからも公開されています。

https://itunes.apple.com/us/book/swift-programming-language/id881256329?mt=11

 

以下、テストプログラムを作成中のときに気づいたことを覚書に。

遅延初期化

次のコードはCoreDataのsqliteファイルを読み込む処理です。

lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = {

    var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)

    let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent(“MasterDetailTest.sqlite”)

    // 以下略

    return coordinator

}()

lazyとは遅延プロパティ(インスタンスを生成した際は処理されずに変数アクセス時にコールされる)とのこと。

lazy stored property is a property whose initial value is not calculated until the first time it is used. You indicate a lazy stored property by writing the lazy modifier before its declaration.

Objective-Cでは

    if (_persistentStoreCoordinator != nil) {

        return_persistentStoreCoordinator;

    }

という記述が必要でしたが、変数のアクセス時にnilチェックがいらないってことですごく便利です。

sqliteの格納場所

CoreDataを使ったアプリ作成の際に、いままでの格納フォルダが変更されていました。

正式版リリースでは元に戻るのかな?

以前の場所

Users/ユーザー/Library/Application Support/iPhone Simulator/iOSのバージョン/Applications/ランダムな識別子/Documents/

変更後

Users/ユーザー/Library/Developer/CoreSimulator/Devices/ランダムな識別子/data/Containers/Data/Application/ランダムな識別子/Documents/

 

以下の関数でアプリケーションURLが取得できます。

[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]

 

また何かあれば追記していきます。

 

ad

関連記事

[Objective-C] デリゲート (Delegate)を理解する!

デリゲートとは? デリゲートに関しての意味合いとして、”委譲”とか”代理”と説明されることが多いで

記事を読む

[Objective-C] iPhoneアプリからのメーラー起動

今回はiPhoneアプリからメーラーを起動する処理を紹介します。 メーラー起動のコントローラー

記事を読む

no image

爆走中!

挫折街道爆走中です! が! 迷走中でもあるわけです、はい。 そんな中で、迷走するに至った訳

記事を読む

[Swift] Asset Catalogについて

XCode5から追加されたAsset Catalog。 いままで標準のImages.xcasset

記事を読む

[Objective-C] UINavigationControllerのセグエを使って画面遷移をする

画面遷移の実装 今回はUINavigationControllerを使って画面遷移をしたいと思いま

記事を読む

[Swift] スクリーンサイズを取得する

スクリーンサイズを取得 iPhoneの幅と高さを取得する関数を紹介します。 iOS8から画面の傾

記事を読む

[Swift] Swiftでいろんなfor文まとめてみた

いろんなfor文 プログラム作成で必ず出てくるfor文を自分なりにまとめてみました。 Swift

記事を読む

[Swift] ビルド時のエラー&iOS8でNSBigDecimalのバグ

ビルド時のエラー Swiftプロジェクトを実行中に以下のエラーが出ました。 "__TFSs15_

記事を読む

[iPhone App] WorkManager 1.2.0版がリリースされました。

新機能 以前から要望などが多かったものを元に、機能を追加いたしました。 新バージョンで追加された

記事を読む

no image

小さなことからコツコツと

これまでHTMLとCSSだけで生きてきただけあって、プログラム言語がいまいちわからない。 Mo

記事を読む

ad

Message

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

ad

[PHP] curl転送してみる(googleに)

curlでgoogle画像検索APIにアクセスしてみます。 cu

[PHP] PDOでMySQLの接続確認をする

PDO PHPでMySQLに接続する際には、mysql_connec

[PHP] ランダムな英数字を生成する

便利系メソッド 今回はPHPでランダムな英数字を作成してみます。

[Swift] プロパティリスト(plist)の値を取得

plistからデータを取得してみます。 こちらのエントリーも参考にし

[Swift] Asset Catalogについて

XCode5から追加されたAsset Catalog。 いままで標準

→もっと見る

  • 1978年の七夕生まれ。 25才でweb業界の門を叩き、28才でフリーランスに。 現在は、フリーランスでマークアップ中心に、wordpressのカスタマイズやデザインをしております。 また、iPhoneアプリの開発もしております。

Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/users/1/juny/web/hidef/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524
PAGE TOP ↑

Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/users/1/juny/web/hidef/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524