2016-06-10 4 views
-4

폴더에서 파일을 읽거나 액세스하는 방법. 폴더가 지원 파일 폴더에 추가됩니다.Swift : 폴더에서 파일을 읽는 방법

도와주세요.

미리 감사드립니다.

+0

http://www.techotopia.com/index.php/Working_with_Files_in_Swift_on_iOS_8 –

답변

1

pathForResource를 통해 파일을로드하고 NSData를 통해 파일을 읽을 수 있습니다. 이 JSON 파일의 예입니다

if let path = NSBundle.mainBundle().pathForResource("yourFileName", ofType: "yourFileExtension") { 
     do { 
      let data = try NSData(contentsOfURL: NSURL(fileURLWithPath: path), options: NSDataReadingOptions.DataReadingMappedIfSafe) 
      if let newObj = (try? NSJSONSerialization.JSONObjectWithData(data, options:[])) as? NSDictionary { 
       //on success do what you need... 
      } 
     } catch let error as NSError { 
      //failure... 
     } 
    } 
관련 문제