Skip to content

Instantly share code, notes, and snippets.

@enomoto
Created April 27, 2018 07:52
Show Gist options
  • Save enomoto/dc498933ddc44f34308b4ffa005d781b to your computer and use it in GitHub Desktop.
Save enomoto/dc498933ddc44f34308b4ffa005d781b to your computer and use it in GitHub Desktop.
iOSプロジェクトのテストバンドルに存在するファイルを取得する ref: https://qiita.com/enomotok_/items/27d132969b41bcd26187
let path = Bundle.main.path(forResource: "foo", ofType: "json")
let data: NSData? = try? NSData(contentsOfFile: path!, options: .uncached)
let testBundle = Bundle(for: type(of: self))
let path = testBundle.url(forResource: "bar", withExtension: "json")
let data: NSData? = try? NSData(contentsOf: path!, options: .uncached)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment