LoginSignup
17
17

More than 5 years have passed since last update.

Playgroundでリソース(plist、xml等々)にアクセスする

Last updated at Posted at 2015-05-05

すぐに値や結果を見られて便利なので、Playgroundで小さく作って検証し、本体プロジェクトに組み込んでいます。
その際、plistにどうやったらアクセスできるか調べましたが、できると幸せになれたので書いてみます。

手順

パッケージの内容を表示

まず、Playgroundファイルを右クリックしてメニューを表示し、パッケージの内容を表示を選択します。

スクリーンショット_2015-05-05_11_48_36.png

Resourcesフォルダの設置

パッケージの内容が表示されたら、Resourcesフォルダを設置します。

スクリーンショット_2015-05-05_11_49_10.png

リソース設置

Resourcesフォルダ内にリソースファイルを置きます。
例では適当なplistを置いてみました。

スクリーンショット 2015-05-05 11.52.05.png

これだけでOKです!

アクセス方法

先の例で設置したplistにアクセスする場合は、こんな感じでいけます。

let dict = NSDictionary(contentsOfFile: NSBundle.mainBundle().pathForResource("My", ofType: "plist")!)

他の種類のリソースファイルでもアクセスできますので、ご活用ください。

17
17
2

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
17
17