khanirteza
11/27/2017 - 6:54 PM

RetrieveAPIKey

/// Retrieve key from the plist file.
///
/// - Parameter named: Name of the the key to be retrived.
/// - Returns: Key in string format, return nil if key not found
static func retrieveKeyFor(_ named: String) -> String? {
	guard let path = Bundle.main.path(forResource: "Keys", ofType: "plist") else {
		fatalError("Keys plist not found")
	}
	let data = FileManager.default.contents(atPath: path)
	var format = PropertyListSerialization.PropertyListFormat.xml
	do{
		let keys = try PropertyListSerialization.propertyList(from: data!, options: [], format: &format) as! [String:String]
		return keys[named.rawValue]
	} catch let error{
		print(error)
	}
	
	return nil
}