mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-05 23:38:38 +09:00
Dactyloidae iOS initial commit
This commit is contained in:
parent
daa6179d22
commit
7154a0497e
2123 changed files with 197052 additions and 0 deletions
41
mobile/ios/Shared/Extensions/NSCoderExtensions.swift
Normal file
41
mobile/ios/Shared/Extensions/NSCoderExtensions.swift
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import Foundation
|
||||
|
||||
/**
|
||||
* There are some oddnesses around the different ways that NSKeyedArchiver decodes objects based on whether or not they were
|
||||
* originally encoded using Swift 2.x or Swift 3.
|
||||
* If the object was encoded on Swift 2.x, then you need to use decodeObject to unwrap it. But that will return a nil if the object was encoded on Swift 3
|
||||
* For swift 3 encoded objects to you need to use decode<Type>
|
||||
* These helper functions provide a unified way of achieving that
|
||||
**/
|
||||
extension NSCoder {
|
||||
/**
|
||||
* Decode as Int regardless of which Swift version was used to encode it
|
||||
**/
|
||||
open func decodeAsInt(forKey key: String) -> Int {
|
||||
return self.decodeObject(forKey: key) as? Int ?? self.decodeInteger(forKey: key)
|
||||
}
|
||||
/**
|
||||
* Decode as UInt64 regardless of which Swift version was used to encode it
|
||||
**/
|
||||
open func decodeAsUInt64(forKey key: String) -> UInt64 {
|
||||
return (self.decodeObject(forKey: key) as? NSNumber)?.uint64Value ?? UInt64(self.decodeInt64(forKey: key))
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode as Bool regardless of which Swift version was used to encode it
|
||||
**/
|
||||
open func decodeAsBool(forKey key: String) -> Bool {
|
||||
return self.decodeObject(forKey: key) as? Bool ?? self.decodeBool(forKey: key)
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode as Double regardless of which Swift version was used to encode it
|
||||
**/
|
||||
open func decodeAsDouble(forKey key: String) -> Double {
|
||||
return (self.decodeObject(forKey: key) as? NSNumber)?.doubleValue ?? self.decodeDouble(forKey: key)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue