IOS-1455 weak IOS-1455
authorXavier Algarra <xavier@pep-project.org>
Tue, 12 Feb 2019 15:39:47 +0100
branchIOS-1455
changeset 761719410eed7a28
parent 7616 0ed2059a0f71
child 7618 98de33f9d0ba
IOS-1455 weak
pEpForiOS.xcodeproj/project.pbxproj
pEpForiOS/Util/Weak.swift
pEpUtilities/pEpUtilities/pEpUtilities.xcodeproj/project.pbxproj
pEpUtilities/pEpUtilities/pEpUtilities/Foundation/Weak.swift
     1.1 --- a/pEpForiOS.xcodeproj/project.pbxproj	Tue Feb 12 15:04:30 2019 +0100
     1.2 +++ b/pEpForiOS.xcodeproj/project.pbxproj	Tue Feb 12 15:39:47 2019 +0100
     1.3 @@ -203,7 +203,6 @@
     1.4  		15BBBC681FD04DFC00B9DCC8 /* ReportingErrorContainerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15BBBC671FD04DFC00B9DCC8 /* ReportingErrorContainerTest.swift */; };
     1.5  		15BBBC6B1FD0527200B9DCC8 /* DisplayUserErrorTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15BBBC6A1FD0527200B9DCC8 /* DisplayUserErrorTest.swift */; };
     1.6  		15BBBC6C1FD05F4300B9DCC8 /* DisplayUserError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 152130531FD00B7A00688DF2 /* DisplayUserError.swift */; };
     1.7 -		15C5F2461F823752007DE086 /* SortedSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15C5F2451F823752007DE086 /* SortedSet.swift */; };
     1.8  		15D4399A216E697700EB3933 /* AccountPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15D43999216E697700EB3933 /* AccountPickerView.swift */; };
     1.9  		15D4399C216E698E00EB3933 /* AccountPickerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15D4399B216E698E00EB3933 /* AccountPickerViewModel.swift */; };
    1.10  		15D439A5216F7E0E00EB3933 /* AccountPickerViewModelTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15D439A4216F7E0E00EB3933 /* AccountPickerViewModelTest.swift */; };
    1.11 @@ -488,7 +487,6 @@
    1.12  		43F6DFD71DEEC752006B526F /* FetchMessagesOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F6DFD61DEEC752006B526F /* FetchMessagesOperation.swift */; };
    1.13  		43F7F07A1F6AD44600BDF151 /* HandshakeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F7F0791F6AD44600BDF151 /* HandshakeTests.swift */; };
    1.14  		43F7F07C1F6AD4FD00BDF151 /* HandshakeTests_mail_001.txt in Resources */ = {isa = PBXBuildFile; fileRef = 43F7F07B1F6AD4FD00BDF151 /* HandshakeTests_mail_001.txt */; };
    1.15 -		43F848491EAA09AE00DBE460 /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F848481EAA09AE00DBE460 /* Weak.swift */; };
    1.16  		43F84CD21CD899760092FCAE /* SyncFoldersFromServerOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F84CD11CD899760092FCAE /* SyncFoldersFromServerOperation.swift */; };
    1.17  		43F8D80220C537640038ABD5 /* ThreadedMessageFolderProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F8D80120C537640038ABD5 /* ThreadedMessageFolderProtocol.swift */; };
    1.18  		43F8D80420C538740038ABD5 /* ThreadUnAwareFolderFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F8D80320C538740038ABD5 /* ThreadUnAwareFolderFactory.swift */; };
    1.19 @@ -795,7 +793,6 @@
    1.20  		15BBBC621FD0496800B9DCC8 /* ReportingErrorContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportingErrorContainer.swift; sourceTree = "<group>"; };
    1.21  		15BBBC671FD04DFC00B9DCC8 /* ReportingErrorContainerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportingErrorContainerTest.swift; sourceTree = "<group>"; };
    1.22  		15BBBC6A1FD0527200B9DCC8 /* DisplayUserErrorTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayUserErrorTest.swift; sourceTree = "<group>"; };
    1.23 -		15C5F2451F823752007DE086 /* SortedSet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortedSet.swift; sourceTree = "<group>"; };
    1.24  		15D43999216E697700EB3933 /* AccountPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountPickerView.swift; sourceTree = "<group>"; };
    1.25  		15D4399B216E698E00EB3933 /* AccountPickerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountPickerViewModel.swift; sourceTree = "<group>"; };
    1.26  		15D439A4216F7E0E00EB3933 /* AccountPickerViewModelTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountPickerViewModelTest.swift; sourceTree = "<group>"; };
    1.27 @@ -1118,7 +1115,6 @@
    1.28  		43F6DFD61DEEC752006B526F /* FetchMessagesOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchMessagesOperation.swift; sourceTree = "<group>"; };
    1.29  		43F7F0791F6AD44600BDF151 /* HandshakeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HandshakeTests.swift; sourceTree = "<group>"; };
    1.30  		43F7F07B1F6AD4FD00BDF151 /* HandshakeTests_mail_001.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = HandshakeTests_mail_001.txt; sourceTree = "<group>"; };
    1.31 -		43F848481EAA09AE00DBE460 /* Weak.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = "<group>"; };
    1.32  		43F84CD11CD899760092FCAE /* SyncFoldersFromServerOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncFoldersFromServerOperation.swift; sourceTree = "<group>"; };
    1.33  		43F8D80120C537640038ABD5 /* ThreadedMessageFolderProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThreadedMessageFolderProtocol.swift; sourceTree = "<group>"; };
    1.34  		43F8D80320C538740038ABD5 /* ThreadUnAwareFolderFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadUnAwareFolderFactory.swift; sourceTree = "<group>"; };
    1.35 @@ -2311,10 +2307,8 @@
    1.36  				436C232C1E02A2D900071430 /* KickOffMySelfProtocol.swift */,
    1.37  				436C232E1E02A52D00071430 /* LimitedOperationQueue.swift */,
    1.38  				8B69E3981E30F80E0022959E /* Appearance.swift */,
    1.39 -				43F848481EAA09AE00DBE460 /* Weak.swift */,
    1.40  				434F40931EB0B173002FBF0D /* ObservableValue.swift */,
    1.41  				43AE48E61EEFC93900B92BB6 /* DebugMergePolicy.swift */,
    1.42 -				15C5F2451F823752007DE086 /* SortedSet.swift */,
    1.43  				15255B021F825CD100A2CFC9 /* IdentityImageTool.swift */,
    1.44  				155050EF1FE82356009CEAD2 /* UserNotificationTool.swift */,
    1.45  			);
    1.46 @@ -3282,7 +3276,6 @@
    1.47  				43DB81331E2A56BE00A20902 /* AppendMailsOperation.swift in Sources */,
    1.48  				8B69E3991E30F80E0022959E /* Appearance.swift in Sources */,
    1.49  				1544BCFE215246F30075C5A0 /* AttachmentFilter.swift in Sources */,
    1.50 -				43F848491EAA09AE00DBE460 /* Weak.swift in Sources */,
    1.51  				B716056020D3ECC900A733D6 /* MoveToFolderTableViewController.swift in Sources */,
    1.52  				43D755FC1F26382B006F933A /* EmailConnectInfo+Extension.swift in Sources */,
    1.53  				15874BCB2127493E00A3A4A6 /* AccountVerificationResultDelegate.swift in Sources */,
    1.54 @@ -3351,7 +3344,6 @@
    1.55  				1554755F2137F6F8005A52D0 /* SwipeActionDescriptor.swift in Sources */,
    1.56  				43A6E04B1E5726C8005BEE69 /* ReevaluateMessageRatingOperation.swift in Sources */,
    1.57  				15B220521FC2DAE200CA52BA /* InfoPlist+pEpStrings.swift in Sources */,
    1.58 -				15C5F2461F823752007DE086 /* SortedSet.swift in Sources */,
    1.59  				431E2B071F02550C000035FA /* CheckOutgoingMessagesOperation.swift in Sources */,
    1.60  				496355B120ECEA2900AA4387 /* ThreadedEmailViewModel+EmailDisplayDelegate.swift in Sources */,
    1.61  				43D070332133DC500013B120 /* DefaultAppSettings.swift in Sources */,
     2.1 --- a/pEpForiOS/Util/Weak.swift	Tue Feb 12 15:04:30 2019 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,50 +0,0 @@
     2.4 -//
     2.5 -//  Weak.swift
     2.6 -//  pEpForiOS
     2.7 -//
     2.8 -//  Created by Dirk Zimmermann on 21.04.17.
     2.9 -//  Copyright © 2017 p≡p Security S.A. All rights reserved.
    2.10 -//
    2.11 -
    2.12 -import Foundation
    2.13 -
    2.14 -/**
    2.15 - Container for weak values.
    2.16 - Useful for putting weak values into containers like arrays.
    2.17 - */
    2.18 -class Weak<T: AnyObject> {
    2.19 -    weak var value : T?
    2.20 -    init (value: T) {
    2.21 -        self.value = value
    2.22 -    }
    2.23 -}
    2.24 -
    2.25 -/**
    2.26 - Container for weak values that are Hashable and therefore Equatable,
    2.27 - delegating to their values.
    2.28 - Useful for putting weak values into containers like arrays.
    2.29 - */
    2.30 -class WeakHashable<T: AnyObject>: Hashable where T: Hashable {
    2.31 -    weak var value : T?
    2.32 -
    2.33 -    var hashValue: Int {
    2.34 -        return value?.hashValue ?? 0
    2.35 -    }
    2.36 -
    2.37 -    init (value: T) {
    2.38 -        self.value = value
    2.39 -    }
    2.40 -}
    2.41 -
    2.42 -/**
    2.43 - - Note: weakHashable.nil == otherWeakHashable.nil, weakHashable.nil != otherWeakHashable.value.
    2.44 - */
    2.45 -func ==<T>(left: WeakHashable<T>, right: WeakHashable<T>) -> Bool {
    2.46 -    if let l = left.value, let r = right.value {
    2.47 -        return l == r
    2.48 -    }
    2.49 -    if left.value == nil && right.value == nil {
    2.50 -        return true
    2.51 -    }
    2.52 -    return false
    2.53 -}
     3.1 --- a/pEpUtilities/pEpUtilities/pEpUtilities.xcodeproj/project.pbxproj	Tue Feb 12 15:04:30 2019 +0100
     3.2 +++ b/pEpUtilities/pEpUtilities/pEpUtilities.xcodeproj/project.pbxproj	Tue Feb 12 15:39:47 2019 +0100
     3.3 @@ -41,6 +41,8 @@
     3.4  		B7A46C5E220DBAF00027CCB5 /* OperationQueue+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7A46C5D220DBAF00027CCB5 /* OperationQueue+Extension.swift */; };
     3.5  		B7A46C62220DCEA80027CCB5 /* NSAttributedString+Parsing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7A46C61220DCEA80027CCB5 /* NSAttributedString+Parsing.swift */; };
     3.6  		B7DB7F4E2213098B003968DA /* SortedSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7DB7F4D2213098A003968DA /* SortedSet.swift */; };
     3.7 +		B7DB7F5022130DE9003968DA /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7DB7F4F22130DE9003968DA /* Weak.swift */; };
     3.8 +		B7DB7F522213120B003968DA /* SortedSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7DB7F512213120B003968DA /* SortedSet.swift */; };
     3.9  /* End PBXBuildFile section */
    3.10  
    3.11  /* Begin PBXFileReference section */
    3.12 @@ -80,6 +82,8 @@
    3.13  		B7A46C5D220DBAF00027CCB5 /* OperationQueue+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OperationQueue+Extension.swift"; sourceTree = "<group>"; };
    3.14  		B7A46C61220DCEA80027CCB5 /* NSAttributedString+Parsing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+Parsing.swift"; sourceTree = "<group>"; };
    3.15  		B7DB7F4D2213098A003968DA /* SortedSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SortedSet.swift; sourceTree = "<group>"; };
    3.16 +		B7DB7F4F22130DE9003968DA /* Weak.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = "<group>"; };
    3.17 +		B7DB7F512213120B003968DA /* SortedSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SortedSet.swift; path = ../../../../pEpForiOS/Util/SortedSet.swift; sourceTree = "<group>"; };
    3.18  /* End PBXFileReference section */
    3.19  
    3.20  /* Begin PBXFrameworksBuildPhase section */
    3.21 @@ -109,8 +113,10 @@
    3.22  				B70A3A5422005BD400EDCE61 /* Date+Extension.swift */,
    3.23  				B70A3A5622005BE300EDCE61 /* NSRegularExpression+Extension.swift */,
    3.24  				B7911ECB21F8B46600D7F66F /* GCD.swift */,
    3.25 +				B7DB7F4F22130DE9003968DA /* Weak.swift */,
    3.26  				B7A46C5D220DBAF00027CCB5 /* OperationQueue+Extension.swift */,
    3.27  				B7465DBD22119D39008A1708 /* Thread+Extension.swift */,
    3.28 +				B7DB7F512213120B003968DA /* SortedSet.swift */,
    3.29  				B7465DC522119EB1008A1708 /* Array+SortingAndSearching.swift */,
    3.30  			);
    3.31  			path = Foundation;
    3.32 @@ -271,6 +277,7 @@
    3.33  				B7911EC221F8694100D7F66F /* UIColor+Extension.swift in Sources */,
    3.34  				B753907E2212D6B500B1FCF9 /* CGSize+Extension.swift in Sources */,
    3.35  				B75390802212DD0600B1FCF9 /* UIView+Util.swift in Sources */,
    3.36 +				B7DB7F522213120B003968DA /* SortedSet.swift in Sources */,
    3.37  				B7DB7F4E2213098B003968DA /* SortedSet.swift in Sources */,
    3.38  				B7911EC621F88AF800D7F66F /* UIImage+Extension.swift in Sources */,
    3.39  				B70A3A77220091D400EDCE61 /* Logger.swift in Sources */,
    3.40 @@ -279,6 +286,7 @@
    3.41  				B70A3A5722005BE300EDCE61 /* NSRegularExpression+Extension.swift in Sources */,
    3.42  				B7911ECA21F88D1900D7F66F /* UITableView+Extension.swift in Sources */,
    3.43  				B7465DBE22119D3A008A1708 /* Thread+Extension.swift in Sources */,
    3.44 +				B7DB7F5022130DE9003968DA /* Weak.swift in Sources */,
    3.45  				B7A46C52220C732E0027CCB5 /* Data+Extensions.swift in Sources */,
    3.46  				B7465DC82211A062008A1708 /* SegueHandlerType.swift in Sources */,
    3.47  				B75390822212DFB600B1FCF9 /* UINavigationController+Extensions.swift in Sources */,
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/pEpUtilities/pEpUtilities/pEpUtilities/Foundation/Weak.swift	Tue Feb 12 15:39:47 2019 +0100
     4.3 @@ -0,0 +1,50 @@
     4.4 +//
     4.5 +//  Weak.swift
     4.6 +//  pEpForiOS
     4.7 +//
     4.8 +//  Created by Dirk Zimmermann on 21.04.17.
     4.9 +//  Copyright © 2017 p≡p Security S.A. All rights reserved.
    4.10 +//
    4.11 +
    4.12 +import Foundation
    4.13 +
    4.14 +/**
    4.15 + Container for weak values.
    4.16 + Useful for putting weak values into containers like arrays.
    4.17 + */
    4.18 +class Weak<T: AnyObject> {
    4.19 +    weak var value : T?
    4.20 +    init (value: T) {
    4.21 +        self.value = value
    4.22 +    }
    4.23 +}
    4.24 +
    4.25 +/**
    4.26 + Container for weak values that are Hashable and therefore Equatable,
    4.27 + delegating to their values.
    4.28 + Useful for putting weak values into containers like arrays.
    4.29 + */
    4.30 +class WeakHashable<T: AnyObject>: Hashable where T: Hashable {
    4.31 +    weak var value : T?
    4.32 +
    4.33 +    var hashValue: Int {
    4.34 +        return value?.hashValue ?? 0
    4.35 +    }
    4.36 +
    4.37 +    init (value: T) {
    4.38 +        self.value = value
    4.39 +    }
    4.40 +}
    4.41 +
    4.42 +/**
    4.43 + - Note: weakHashable.nil == otherWeakHashable.nil, weakHashable.nil != otherWeakHashable.value.
    4.44 + */
    4.45 +func ==<T>(left: WeakHashable<T>, right: WeakHashable<T>) -> Bool {
    4.46 +    if let l = left.value, let r = right.value {
    4.47 +        return l == r
    4.48 +    }
    4.49 +    if left.value == nil && right.value == nil {
    4.50 +        return true
    4.51 +    }
    4.52 +    return false
    4.53 +}