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

関連記事

[Swift] CoreDataを使ってみる

SwiftでCoreData 今回はSwiftでCoreDataを使ってみます。 Xcodeプロ

記事を読む

[Swift] Asset Catalogについて

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

記事を読む

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

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

記事を読む

[Swift] 定数クラスをつくってみる

Objective-cの場合 今回は共通にする定数をまとめるクラスを作ってみます。 まずはO

記事を読む

no image

一旦、離脱中!

サイト制作の仕事がちょろちょろちょろっと入ってきたので、寂しいけれどしばしXcodeとはお別れ。

記事を読む

iPhoneApp WorkManager公開されました!

きっとリジェクトされるんだろうなと思いながら申請を出して1週間。 本日、公開のメールが届きまし

記事を読む

備忘録的メモ

Xcode5にアップデートして、とりあえずアプリを走らせてみたらナビゲーションバーがかぶってる・・・

記事を読む

[Objective-C] 小数点を丸める!(数値変換)

小数点を含む数値 Objective-Cに限らず、小数点を含む数値を計算する場合はdoubleやf

記事を読む

[Objective-C] 文字列操作の便利Tips

Tipsいろいろ 先日の投稿 共通関数をまとめたクラスを作ろう!の流れで、文字列を操作するときに便

記事を読む

[Swift] optional値の設定(??)

optional値がnilの時 プロジェクトでのテンプレートを選択した時にソースコードが自動生成さ

記事を読む

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