Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ChristianKienle/7615425536be3b71ef6d893389b49a14 to your computer and use it in GitHub Desktop.
Save ChristianKienle/7615425536be3b71ef6d893389b49a14 to your computer and use it in GitHub Desktop.
//
// PropertyList.swift
// CruiseKit
//
// Created by cmk on 15/07/16.
// Copyright © 2016 Christian Kienle. All rights reserved.
//
import Foundation
public enum PropertyList {
public static func arrayPropertyList(fromData data: NSData) -> PropertyList? {
do {
let plist = try NSPropertyListSerialization.propertyListWithData(data, options: .Immutable, format: nil)
guard let array = plist as? NSArray else {
return nil
}
return PropertyList.array(array: array)
} catch {
print(error)
return nil
}
}
case dictionary(dictionary: NSDictionary)
case array(array: NSArray)
public var dictionaryObject: NSDictionary? {
switch self {
case .dictionary(let dictionary): return dictionary
default: return nil
}
}
public var arrayObject: NSArray? {
switch self {
case .array(let array): return array
default: return nil
}
}
public var plistObject: NSObject? {
return arrayObject ?? dictionaryObject
}
}
public protocol PropertyListRepresentable {
var propertyListObject: PropertyList { get }
}
public protocol PropertyListCreatable {
static func create(withPropertyList propertyList: PropertyList) -> Self?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment