-
-
Save Pasanpr/9cb737a04d0a96dd6b6123b44a1656e4 to your computer and use it in GitHub Desktop.
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
enum PlistError: Error { | |
case invalidResource | |
case parsingFailure | |
} | |
class PlistLoader { | |
static func array(fromFile name: String, ofType type: String) throws -> [[String: String]] { | |
guard let path = Bundle.main.path(forResource: name, ofType: type) else { | |
throw PlistError.invalidResource | |
} | |
guard let array = NSArray(contentsOfFile: path) as? [[String: String]] else { | |
throw PlistError.parsingFailure | |
} | |
return array | |
} | |
} | |
class ContactsSource { | |
static var contacts: [Contact] { | |
let data = try! PlistLoader.array(fromFile: "ContactsDB", ofType: "plist") | |
return data.flatMap { Contact(dictionary: $0) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment