merge IOS-1558 refactor
authorAlejandro Gelos <alejandro@pep-project.org>
Fri, 17 May 2019 14:19:17 +0200
branchrefactor
changeset 8672166ae0c2051e
parent 8669 e16f27101ac0
parent 8671 0eac048db37e
child 8674 00e6d9c5ecfb
child 8675 5f2786cc6ce7
merge IOS-1558
     1.1 --- a/subModules/pEpIOSToolbox/pEpIOSToolbox.xcodeproj/project.pbxproj	Fri May 17 14:08:50 2019 +0200
     1.2 +++ b/subModules/pEpIOSToolbox/pEpIOSToolbox.xcodeproj/project.pbxproj	Fri May 17 14:19:17 2019 +0200
     1.3 @@ -7,6 +7,7 @@
     1.4  	objects = {
     1.5  
     1.6  /* Begin PBXBuildFile section */
     1.7 +		370DB3CF22804A3600BC929A /* NSSecureCoding+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 370DB3CE22804A3600BC929A /* NSSecureCoding+Extension.swift */; };
     1.8  		378B76552240F93A00D6662C /* TestUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 378B76542240F93A00D6662C /* TestUtils.swift */; };
     1.9  		37904562223FA486006DAB3B /* NetworkReachabilityProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3790455E223FA486006DAB3B /* NetworkReachabilityProtocol.swift */; };
    1.10  		37904563223FA486006DAB3B /* Reachability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3790455F223FA486006DAB3B /* Reachability.swift */; };
    1.11 @@ -55,6 +56,7 @@
    1.12  /* End PBXContainerItemProxy section */
    1.13  
    1.14  /* Begin PBXFileReference section */
    1.15 +		370DB3CE22804A3600BC929A /* NSSecureCoding+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSSecureCoding+Extension.swift"; sourceTree = "<group>"; };
    1.16  		378B76542240F93A00D6662C /* TestUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestUtils.swift; path = ../../../../Submodules/pEpIOSToolbox/pEpIOSToolboxTests/TestUtils/TestUtils.swift; sourceTree = "<group>"; };
    1.17  		3790455E223FA486006DAB3B /* NetworkReachabilityProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkReachabilityProtocol.swift; sourceTree = "<group>"; };
    1.18  		3790455F223FA486006DAB3B /* Reachability.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reachability.swift; sourceTree = "<group>"; };
    1.19 @@ -176,6 +178,7 @@
    1.20  		B70A3A5222005A7600EDCE61 /* Foundation */ = {
    1.21  			isa = PBXGroup;
    1.22  			children = (
    1.23 +				370DB3CE22804A3600BC929A /* NSSecureCoding+Extension.swift */,
    1.24  				B7911ECB21F8B46600D7F66F /* GCD.swift */,
    1.25  				B7A46C51220C732E0027CCB5 /* Data+Extensions.swift */,
    1.26  				B7A46C53220C73BE0027CCB5 /* String+Extensions.swift */,
    1.27 @@ -393,6 +396,7 @@
    1.28  				B70A3A77220091D400EDCE61 /* Logger.swift in Sources */,
    1.29  				B7A46C56220DA5EB0027CCB5 /* Substring+Email.swift in Sources */,
    1.30  				B7A46C5E220DBAF00027CCB5 /* OperationQueue+Extension.swift in Sources */,
    1.31 +				370DB3CF22804A3600BC929A /* NSSecureCoding+Extension.swift in Sources */,
    1.32  				B70A3A5722005BE300EDCE61 /* NSRegularExpression+Extension.swift in Sources */,
    1.33  				B7465DBE22119D3A008A1708 /* Thread+Extension.swift in Sources */,
    1.34  				B7DB7F5022130DE9003968DA /* Weak.swift in Sources */,
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/subModules/pEpIOSToolbox/pEpIOSToolbox/Foundation/NSSecureCoding+Extension.swift	Fri May 17 14:19:17 2019 +0200
     2.3 @@ -0,0 +1,30 @@
     2.4 +//
     2.5 +//  NSSecureCoding+Extension.swift
     2.6 +//  pEp
     2.7 +//
     2.8 +//  Created by Dirk Zimmermann on 19.01.18.
     2.9 +//  Copyright © 2018 p≡p Security S.A. All rights reserved.
    2.10 +//
    2.11 +
    2.12 +import Foundation
    2.13 +
    2.14 +extension NSSecureCoding {
    2.15 +    /**
    2.16 +     Reconstructs an object from a string, that was created using `persistBase64Encoded()`.
    2.17 +     */
    2.18 +    public static func from(base64Encoded: String) -> Any? {
    2.19 +        guard let data = Data(base64Encoded: base64Encoded) else {
    2.20 +            return nil
    2.21 +        }
    2.22 +        return NSKeyedUnarchiver.unarchiveObject(with: data)
    2.23 +    }
    2.24 +
    2.25 +    /**
    2.26 +     Persists itself into a string, using Base64 as the encoding.
    2.27 +     Works in tandem with `from(base64Encoded:)`.
    2.28 +     */
    2.29 +    public func persistBase64Encoded() -> String {
    2.30 +        let data = NSKeyedArchiver.archivedData(withRootObject: self)
    2.31 +        return data.base64EncodedString()
    2.32 +    }
    2.33 +}