8
10

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.

playground でファイル読み込みをする (画像・テキストファイルなど)

Last updated at Posted at 2015-11-26

playground 内に Resources というディレクトリがあるので、そこにファイルを置いてあげればアクセスできます!

ディレクトリがない場合

Resources ディレクトリがない場合は作りましょう。

playground -> "パッケージの内容を表示" -> Resources ディレクトリ作成

または

mkdir 作業中のplayground.playground/Resources

読み込み方

// 画像
let image = UIImage(named: "sample")

// テキスト
let path = NSBundle.mainBundle().pathForResource("sample", ofType: "json")
let contents = try! String(contentsOfFile: path!, encoding: NSUTF8StringEncoding)
8
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
8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?