Skip to content

Instantly share code, notes, and snippets.

@KyleGoslan
Created August 3, 2016 21:03
Show Gist options
  • Save KyleGoslan/457c980d7a076524c2fb9a2993d7ab0b to your computer and use it in GitHub Desktop.
Save KyleGoslan/457c980d7a076524c2fb9a2993d7ab0b to your computer and use it in GitHub Desktop.
Protocol that loads some JSON from a file in the main bundle (Uses SwiftyJSON).
import Foundation
import SwiftyJSON
protocol DataLoader { }
extension DataLoader {
func loadJSON(fileName: String, type: String = "json") -> JSON? {
let filePath = NSBundle.mainBundle().pathForResource(fileName, ofType: type)
if let data = NSData(contentsOfFile: filePath!) {
let json = JSON(data: data)
return json
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment