0001    // Property.swift
0002    //
0003    // Copyright (c) 2015 Oven Bits, LLC
0004    //
0005    // Permission is hereby granted, free of charge, to any person obtaining a copy
0006    // of this software and associated documentation files (the "Software"), to deal
0007    // in the Software without restriction, including without limitation the rights
0008    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0009    // copies of the Software, and to permit persons to whom the Software is
0010    // furnished to do so, subject to the following conditions:
0011    //
0012    // The above copyright notice and this permission notice shall be included in all
0013    // copies or substantial portions of the Software.
0014    //
0015    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0018    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0019    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0020    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0021    // SOFTWARE.
0022    
0023    import Foundation
0024    
0025    final public class Property
Property.swift:105
extension Property: CustomStringConvertible {
Property.swift:123
extension Property: CustomDebugStringConvertible {
Property.swift:131
extension Property: Hashable {
Property.swift:139
extension Property: Equatable {}
Property.swift:141
public func ==<T: Equatable>(lhs: Property<T>, rhs: Property<T>) -> Bool {
Property.swift:141
public func ==<T: Equatable>(lhs: Property<T>, rhs: Property<T>) -> Bool {
Property.swift:145
public func ==<T>(lhs: Property<T>, rhs: Property<T>) -> Bool {
Property.swift:145
public func ==<T>(lhs: Property<T>, rhs: Property<T>) -> Bool {
<T
Property.swift:26
    public typealias PropertyType = T
: JSONTransformable>: PropertyDescription { 0026 public typealias PropertyType
Property.swift:29
    public var value: PropertyType?
Property.swift:32
    public var postProcess: ((PropertyType?) -> Void)?
Property.swift:39
        return "\(PropertyType.self)"
Property.swift:53
    public init(key: String, defaultValue: PropertyType? = nil, required: Bool = false, postProcess: ((PropertyType?) -> Void)? = nil) {
Property.swift:53
    public init(key: String, defaultValue: PropertyType? = nil, required: Bool = false, postProcess: ((PropertyType?) -> Void)? = nil) {
Property.swift:70
        if let newValue = PropertyType.fromJSON(jsonValue) as? PropertyType {
Property.swift:70
        if let newValue = PropertyType.fromJSON(jsonValue) as? PropertyType {
Property.swift:97
        if let decodedValue = decoder.decodeObjectForKey(key) as? PropertyType {
= T 0027 0028 /// Backing store for property data 0029 public var value
Property.swift:47
        get { return value }
Property.swift:46
        set { value = newValue }
Property.swift:55
        self.value = defaultValue
Property.swift:71
            value = newValue
Property.swift:74
        return (value != nil)
Property.swift:79
        return value?.toJSON()
Property.swift:84
        postProcess?(value)
Property.swift:91
        if let object: AnyObject = value as? AnyObject {
Property.swift:98
            value = decodedValue
Property.swift:109
        if let value = value {
Property.swift:142
    return lhs.key == rhs.key && lhs.value == rhs.value
Property.swift:142
    return lhs.key == rhs.key && lhs.value == rhs.value
: PropertyType? 0030 0031 /// Post-processing closure. 0032 public var postProcess
Property.swift:57
        self.postProcess = postProcess
Property.swift:84
        postProcess?(value)
: ((PropertyType?) -> Void)? 0033 0034 /// JSON parameter key 0035 public var key
Property.swift:54
        self.key = key
Property.swift:66
        key.componentsSeparatedByString(".").forEach {
Property.swift:92
            coder.encodeObject(object, forKey: key)
Property.swift:97
        if let decodedValue = decoder.decodeObjectForKey(key) as? PropertyType {
Property.swift:108
        var string = "Property<\(type)> (key: \(key), value: "
Property.swift:133
        return key.hashValue
Property.swift:142
    return lhs.key == rhs.key && lhs.value == rhs.value
Property.swift:142
    return lhs.key == rhs.key && lhs.value == rhs.value
Property.swift:146
    return lhs.key == rhs.key
Property.swift:146
    return lhs.key == rhs.key
: String 0036 0037 /// Type information 0038 public var type
Property.swift:108
        var string = "Property<\(type)> (key: \(key), value: "
: String { 0039 return "\(PropertyType.self)" 0040 } 0041 0042 /// Specify whether value is required 0043 public var required
Property.swift:56
        self.required = required
Property.swift:115
        string += ", required: \(required))"
= false 0044 0045 public subscript() -> PropertyType? { 0046 set { value = newValue } 0047 get { return value } 0048 } 0049 0050 // MARK: Initialization 0051 0052 /// Initialize with JSON property key 0053 public init(key: String, defaultValue: PropertyType? = nil, required: Bool = false, postProcess: ((PropertyType?) -> Void)? = nil) { 0054 self.key = key 0055 self.value = defaultValue 0056 self.required = required 0057 self.postProcess = postProcess 0058 } 0059 0060 // MARK: Transform 0061 0062 /// Extract object from JSON and return whether or not the value was extracted 0063 public func fromJSON(json: JSON) -> Bool { 0064 var jsonValue = json 0065 0066 key.componentsSeparatedByString(".").forEach { 0067 jsonValue = jsonValue[$0] 0068 } 0069 0070 if let newValue = PropertyType.fromJSON(jsonValue) as? PropertyType { 0071 value = newValue 0072 } 0073 0074 return (value != nil) 0075 } 0076 0077 /// Convert object to JSON 0078 public func toJSON() -> AnyObject? { 0079 return value?.toJSON() 0080 } 0081 0082 /// Perform initialization post-processing 0083 public func initPostProcess() { 0084 postProcess?(value) 0085 } 0086 0087 // MARK: Coding 0088 0089 /// Encode 0090 public func encode(coder: NSCoder) { 0091 if let object: AnyObject = value as? AnyObject { 0092 coder.encodeObject(object, forKey: key) 0093 } 0094 } 0095 0096 public func decode(decoder: NSCoder) { 0097 if let decodedValue = decoder.decodeObjectForKey(key) as? PropertyType { 0098 value = decodedValue 0099 } 0100 } 0101 } 0102 0103 // MARK:- CustomStringConvertible 0104 0105 extension Property: CustomStringConvertible { 0106 public var description
Property.swift:125
        return description
: String { 0107 0108 var string = "Property<\(type)> (key: \(key), value: " 0109 if let value = value { 0110 string += "\(value)" 0111 } 0112 else { 0113 string += "nil" 0114 } 0115 string += ", required: \(required))" 0116 0117 return string 0118 } 0119 } 0120 0121 // MARK:- CustomDebugStringConvertible 0122 0123 extension Property: CustomDebugStringConvertible { 0124 public var debugDescription: String { 0125 return description 0126 } 0127 } 0128 0129 // MARK:- Hashable 0130 0131 extension Property: Hashable { 0132 public var hashValue: Int { 0133 return key.hashValue 0134 } 0135 } 0136 0137 // MARK:- Equatable 0138 0139 extension Property: Equatable {} 0140 0141 public func ==<T: Equatable>(lhs: Property<T>, rhs: Property<T>) -> Bool { 0142 return lhs.key == rhs.key && lhs.value == rhs.value 0143 } 0144 0145 public func ==<T>(lhs: Property<T>, rhs: Property<T>) -> Bool { 0146 return lhs.key == rhs.key 0147 } 0148