Created
August 3, 2016 21:03
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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