Created
July 24, 2016 18:45
-
-
Save ChristianKienle/7615425536be3b71ef6d893389b49a14 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// 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