35
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【備忘録】Swiftでプロジェクト内のplistを読み込む方法

Posted at

需要があるかわからないですが、Swiftであらかじめプロジェクトに入れておいた設定ファイル(.plist)を読み込む必要があって、小一時間詰まったのでメモ。

test.plistがtest.swiftと同じ階層にあるなら、次のように書けます。階層が関係するかはわかりませんが。

test.swift
    var filePath = NSBundle.mainBundle().pathForResource("test.plist", ofType:nil )
    var dic = NSDictionary(contentsOfFile:filePath!)

これだけで、.plistファイルをNSDictionary型で取り出せます。
意外と簡単です。

35
31
1

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
35
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?