-
-
Save sturdysturge/3135b388836fc050e86fec710b0f1187 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
struct ContentView: View { | |
static func getPlist(withName name: String) -> NSDictionary? | |
{ | |
guard let path = Bundle.main.path(forResource: name, ofType: "plist"), | |
let xml = FileManager.default.contents(atPath: path), | |
let dictionary = try? PropertyListSerialization.propertyList( | |
from: xml, options: .mutableContainersAndLeaves, format: nil) as? NSDictionary | |
else { return nil } | |
return dictionary | |
} | |
static let plist = getPlist(withName: "Property List") | |
static let person0 = Self.plist?["Person 0"] as? NSDictionary | |
let name = person0?["Name"] as? String | |
let birthday = person0?["Birthday"] as? Date | |
let lovesSwift = person0?["Loves Swift"] as? Bool | |
var dateFormatter: DateFormatter { | |
let formatter = DateFormatter() | |
formatter.dateStyle = .full | |
formatter.timeStyle = .short | |
return formatter | |
} | |
var body: some View { | |
VStack { | |
Text("Name: \(name ?? "No name")") | |
Text("Birthday: \(dateFormatter.string(from: birthday ?? Date()))") | |
Text("Loves Swift: \(lovesSwift ?? false ? "YES!" : "No")") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment