Skip to content

Commit 0859e13

Browse files
authored
Merge pull request ReactiveCocoa#3131 from ReactiveCocoa/property-lifetime
Introduce the `BindingTarget` protocol.
2 parents 978463b + 3cc4c0e commit 0859e13

File tree

8 files changed

+528
-428
lines changed

8 files changed

+528
-428
lines changed

ReactiveCocoa.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@
243243
9A1E72BA1D4DE96500CC20C3 /* KeyValueObservingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A1E72B91D4DE96500CC20C3 /* KeyValueObservingSpec.swift */; };
244244
9A1E72BB1D4DE96500CC20C3 /* KeyValueObservingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A1E72B91D4DE96500CC20C3 /* KeyValueObservingSpec.swift */; };
245245
9A1E72BC1D4DE96500CC20C3 /* KeyValueObservingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A1E72B91D4DE96500CC20C3 /* KeyValueObservingSpec.swift */; };
246+
9A694EF31D5CE02E009B05BD /* UnidirectionalBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A694EF21D5CE02E009B05BD /* UnidirectionalBinding.swift */; };
247+
9A694EF41D5CE02E009B05BD /* UnidirectionalBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A694EF21D5CE02E009B05BD /* UnidirectionalBinding.swift */; };
248+
9A694EF51D5CE02E009B05BD /* UnidirectionalBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A694EF21D5CE02E009B05BD /* UnidirectionalBinding.swift */; };
249+
9A694EF61D5CE02E009B05BD /* UnidirectionalBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A694EF21D5CE02E009B05BD /* UnidirectionalBinding.swift */; };
246250
9ABCB1851D2A5B5A00BCA243 /* Deprecations+Removals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ABCB1841D2A5B5A00BCA243 /* Deprecations+Removals.swift */; };
247251
9ABCB1861D2A5B5A00BCA243 /* Deprecations+Removals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ABCB1841D2A5B5A00BCA243 /* Deprecations+Removals.swift */; };
248252
9ABCB1871D2A5B5A00BCA243 /* Deprecations+Removals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ABCB1841D2A5B5A00BCA243 /* Deprecations+Removals.swift */; };
@@ -923,6 +927,7 @@
923927
7A7065831A3F8967001E8354 /* RACKVOProxySpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RACKVOProxySpec.m; sourceTree = "<group>"; };
924928
7DFBED031CDB8C9500EE435B /* ReactiveCocoaTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ReactiveCocoaTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
925929
9A1E72B91D4DE96500CC20C3 /* KeyValueObservingSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyValueObservingSpec.swift; sourceTree = "<group>"; };
930+
9A694EF21D5CE02E009B05BD /* UnidirectionalBinding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnidirectionalBinding.swift; sourceTree = "<group>"; };
926931
9ABCB1841D2A5B5A00BCA243 /* Deprecations+Removals.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deprecations+Removals.swift"; sourceTree = "<group>"; };
927932
9AD0F0691D48BA4800ADFAB7 /* NSObject+KeyValueObserving.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSObject+KeyValueObserving.swift"; sourceTree = "<group>"; };
928933
A97451331B3A935E00F48E55 /* watchOS-Application.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "watchOS-Application.xcconfig"; sourceTree = "<group>"; };
@@ -1622,6 +1627,7 @@
16221627
D08C54B01A69A2AC00AD8286 /* Property.swift */,
16231628
D08C54B11A69A2AC00AD8286 /* Signal.swift */,
16241629
D08C54B21A69A2AC00AD8286 /* SignalProducer.swift */,
1630+
9A694EF21D5CE02E009B05BD /* UnidirectionalBinding.swift */,
16251631
);
16261632
name = Signals;
16271633
sourceTree = "<group>";
@@ -2427,6 +2433,7 @@
24272433
57A4D1F81BA13D7A00F7D4B1 /* RACSignalSequence.m in Sources */,
24282434
57A4D1F91BA13D7A00F7D4B1 /* RACStream.m in Sources */,
24292435
57A4D1FA1BA13D7A00F7D4B1 /* RACStringSequence.m in Sources */,
2436+
9A694EF61D5CE02E009B05BD /* UnidirectionalBinding.swift in Sources */,
24302437
CD0C45E11CC9A288009F5BF0 /* DynamicProperty.swift in Sources */,
24312438
57A4D1FB1BA13D7A00F7D4B1 /* RACSubject.m in Sources */,
24322439
57A4D1FC1BA13D7A00F7D4B1 /* RACSubscriber.m in Sources */,
@@ -2578,6 +2585,7 @@
25782585
A9B3158D1B3940750001CB9C /* RACKVOTrampoline.m in Sources */,
25792586
A9B3158E1B3940750001CB9C /* RACMulticastConnection.m in Sources */,
25802587
C7142DBE1CDEA194009F402D /* CocoaAction.swift in Sources */,
2588+
9A694EF51D5CE02E009B05BD /* UnidirectionalBinding.swift in Sources */,
25812589
A9B315901B3940750001CB9C /* RACPassthroughSubscriber.m in Sources */,
25822590
A9B315911B3940750001CB9C /* RACQueueScheduler.m in Sources */,
25832591
A9B315921B3940750001CB9C /* RACReplaySubject.m in Sources */,
@@ -2623,6 +2631,7 @@
26232631
D03765D819EDA41200A782A9 /* RACSignal+Operations.m in Sources */,
26242632
D871D69F1B3B29A40070F16C /* Optional.swift in Sources */,
26252633
D08C54B61A69A3DB00AD8286 /* Event.swift in Sources */,
2634+
9A694EF31D5CE02E009B05BD /* UnidirectionalBinding.swift in Sources */,
26262635
D03764F219EDA41200A782A9 /* NSControl+RACTextSignalSupport.m in Sources */,
26272636
D037650219EDA41200A782A9 /* NSFileHandle+RACSupport.m in Sources */,
26282637
D03765E219EDA41200A782A9 /* RACStream.m in Sources */,
@@ -2874,6 +2883,7 @@
28742883
D037662319EDA41200A782A9 /* UIBarButtonItem+RACCommandSupport.m in Sources */,
28752884
D03765A119EDA41200A782A9 /* RACKVOTrampoline.m in Sources */,
28762885
D037665B19EDA41200A782A9 /* UITableViewHeaderFooterView+RACSignalSupport.m in Sources */,
2886+
9A694EF41D5CE02E009B05BD /* UnidirectionalBinding.swift in Sources */,
28772887
D0C312D019EF2A5800984962 /* Bag.swift in Sources */,
28782888
D0D11ABA1A6AE87700C1F8B1 /* Action.swift in Sources */,
28792889
D037650B19EDA41200A782A9 /* NSInvocation+RACTypeParsing.m in Sources */,

ReactiveCocoa/Swift/DynamicProperty.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public final class DynamicProperty<Value>: MutablePropertyProtocol {
3636
}
3737
}
3838

39+
/// The lifetime of the property.
40+
public var lifetime: Lifetime {
41+
return object?.rac_lifetime ?? .empty
42+
}
43+
3944
/// A producer that will create a Key-Value Observer for the given object,
4045
/// send its initial value then all changes over time, and then complete
4146
/// when the observed object has deallocated.

ReactiveCocoa/Swift/Lifetime.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,28 @@ import enum Result.NoError
44
/// Represents the lifetime of an object, and provides a hook to observe when
55
/// the object deinitializes.
66
public final class Lifetime {
7-
/// A signal that sends a Completed event when the lifetime ends.
7+
/// MARK: Type properties and methods
8+
9+
/// A `Lifetime` that has already ended.
10+
public static var empty: Lifetime {
11+
return Lifetime(ended: .empty)
12+
}
13+
14+
/// MARK: Instance properties
15+
16+
/// A signal that sends a `completed` event when the lifetime ends.
817
public let ended: Signal<(), NoError>
918

19+
/// MARK: Initializers
20+
21+
/// Initialize a `Lifetime` object with the supplied ended signal.
22+
///
23+
/// - parameters:
24+
/// - signal: The ended signal.
25+
private init(ended signal: Signal<(), NoError>) {
26+
ended = signal
27+
}
28+
1029
/// Initialize a `Lifetime` from a lifetime token, which is expected to be
1130
/// associated with an object.
1231
///
@@ -16,8 +35,8 @@ public final class Lifetime {
1635
/// - parameters:
1736
/// - token: A lifetime token for detecting the deinitialization of the
1837
/// associated object.
19-
public init(_ token: Token) {
20-
ended = token.ended
38+
public convenience init(_ token: Token) {
39+
self.init(ended: token.ended)
2140
}
2241

2342
/// A token object which completes its signal when it deinitializes.

0 commit comments

Comments
 (0)