0001    //
0002    //  NSValueCastable.swift
0003    //  Decodable
0004    //
0005    //  Created by Johannes Lund on 2016-01-06.
0006    //  Copyright © 2016 anviking. All rights reserved.
0007    //
0008    
0009    import Foundation
0010    
0011    extension Int64: NSValueCastable {}
0012    extension Int32: NSValueCastable {}
0013    extension Int16: NSValueCastable {}
0014    extension Int8: NSValueCastable {}
0015    extension UInt64: NSValueCastable {}
0016    extension UInt32: NSValueCastable {}
0017    extension UInt16: NSValueCastable {}
0018    extension UInt8: NSValueCastable {}
0019    
0020    /// Provides a default implementation of decode() which casts the object to a NSValue and unsafely casts its value as Self. Used to enable decoding to different IntegerTypes from NSNumber.
0021    public protocol NSValueCastable
NSValueCastable.swift:11
extension Int64: NSValueCastable {}
NSValueCastable.swift:12
extension Int32: NSValueCastable {}
NSValueCastable.swift:13
extension Int16: NSValueCastable {}
NSValueCastable.swift:14
extension Int8: NSValueCastable {}
NSValueCastable.swift:15
extension UInt64: NSValueCastable {}
NSValueCastable.swift:16
extension UInt32: NSValueCastable {}
NSValueCastable.swift:17
extension UInt16: NSValueCastable {}
NSValueCastable.swift:18
extension UInt8: NSValueCastable {}
NSValueCastable.swift:23
extension NSValueCastable {
: Decodable {} 0022 0023 extension NSValueCastable { 0024 private typealias PointerOfSelf
NSValueCastable.swift:30
        let pointer = PointerOfSelf.alloc(1)
= UnsafeMutablePointer<Self> // Why do we have to do this? 0025 public static func decode(j: AnyObject) throws -> Self { 0026 guard let value = j as? NSValue else { 0027 throw TypeMismatchError(expectedType: NSValue.self, receivedType: j.dynamicType, object: j) 0028 } 0029 0030 let pointer = PointerOfSelf.alloc(1) 0031 defer { pointer.dealloc(1) } 0032 value.getValue(pointer) 0033 return pointer.move() 0034 } 0035 } 0036