Skip to content

Instantly share code, notes, and snippets.

Last active Jan 11, 2021
What would you like to do?
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