Skip to content

Commit

Permalink
Merge pull request #24 from uber/swift-support
Browse files Browse the repository at this point in the history
Support Swift
  • Loading branch information
neakor committed Feb 25, 2016
2 parents 950cfa4 + 7cfd0b8 commit 950bbff
Show file tree
Hide file tree
Showing 19 changed files with 615 additions and 337 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,47 @@ Signals remember with what data they were last fired with and you can force an o
}];
```

### Swift support

The protocol-based approach described above is the easiest way to define new Signal types. However, these are unfortunately not accessible from Swift code. In order for Swift to understand the type of your signals correctly, you have to create concrete sub-classes for each signal type. Signals provides two macros to do this: `CreateSignalInterface` to create the interface for your sub-class and `CreateSignalImplementation` to create the implementation. You then use the concrete sub-classes when you declare the signals for your class:

```objective-c

// Defines a new Signal interface, a sub-class of UBSignal with the given
// name and parameters
CreateSignalInterface(UBNetworkResultSignal, NSData *result, NSError *error)

@interface UBNetworkRequest

// We declare the signal with the concrete type
@property (nonatomic, readonly) UBNetworkResultSignal *onNetworkResult;

@end


// In your .m-file you also create the implementation for the sub-class

CreateSignalImplementation(UBNetworkResultSignal, NSData *result, NSError *error)

@implementation UBNetworkRequest

- (instancetype)init {
self = [super init];
if (self) {
// You initialize it without a protocol
_onNetworkResult = [[UBNetworkResultSignal alloc] init];
}
return self;
}

- (void)receivedNetworkResult(NSData *data, NSError *error)
{
// And use it as you normally would
_onNetworkResult.fire(myData, myError);
}
```
## Max observers
Expand Down
2 changes: 1 addition & 1 deletion UberSignals.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'UberSignals'
s.version = '2.3.0'
s.version = '2.4.0'
s.license = { :type => 'MIT' }
s.summary = 'Signals is an eventing framework that enables you to implement the Observable pattern without using NSNotifications.'
s.homepage = 'https://github.com/uber/signals-ios'
Expand Down
46 changes: 43 additions & 3 deletions UberSignals.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
5EBEBDBC1C162E6600E8CA02 /* UBSignalObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 72FED2281B2C97D800DCAB7E /* UBSignalObserver.m */; };
5EBEBDBD1C162E6600E8CA02 /* UBSignalObserver+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 72FED2291B2C97D800DCAB7E /* UBSignalObserver+Internal.h */; };
5EBEBDBE1C162E6600E8CA02 /* UberSignals.h in Headers */ = {isa = PBXBuildFile; fileRef = 72FED20B1B2C97C400DCAB7E /* UberSignals.h */; settings = {ATTRIBUTES = (Public, ); }; };
7219981D1C7E92C000551591 /* UBBaseSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = 72B48DF31C7E2A0200296268 /* UBBaseSignal.m */; };
7219981E1C7E92C100551591 /* UBBaseSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = 72B48DF31C7E2A0200296268 /* UBBaseSignal.m */; };
7219981F1C7E92C100551591 /* UBBaseSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = 72B48DF31C7E2A0200296268 /* UBBaseSignal.m */; };
724993251C41DFFE006653CB /* UberSignals.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7249931B1C41DFFE006653CB /* UberSignals.framework */; };
7249933F1C41E1B8006653CB /* UBSignal.h in Headers */ = {isa = PBXBuildFile; fileRef = 72FED2231B2C97D800DCAB7E /* UBSignal.h */; };
724993401C41E1B8006653CB /* UBSignal+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 72FED2251B2C97D800DCAB7E /* UBSignal+Internal.h */; };
Expand All @@ -32,6 +35,10 @@
7249934C1C41E1CE006653CB /* UBSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = 72FED2241B2C97D800DCAB7E /* UBSignal.m */; };
7249934D1C41E1E0006653CB /* UBSignalEmitter.m in Sources */ = {isa = PBXBuildFile; fileRef = 72FED2351B2C97EB00DCAB7E /* UBSignalEmitter.m */; };
7249934E1C41E1E0006653CB /* UBSignalTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 72FED2321B2C97E500DCAB7E /* UBSignalTests.m */; };
728AB04F1C7BA51600D13324 /* SwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 728AB04E1C7BA51600D13324 /* SwiftTests.swift */; };
728AB0511C7BA51600D13324 /* SwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 728AB04E1C7BA51600D13324 /* SwiftTests.swift */; };
72B48DF41C7E2A0200296268 /* UBBaseSignal.h in Headers */ = {isa = PBXBuildFile; fileRef = 72B48DF21C7E2A0200296268 /* UBBaseSignal.h */; };
72B48DF51C7E2A0200296268 /* UBBaseSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = 72B48DF31C7E2A0200296268 /* UBBaseSignal.m */; };
72FED20C1B2C97C400DCAB7E /* UberSignals.h in Headers */ = {isa = PBXBuildFile; fileRef = 72FED20B1B2C97C400DCAB7E /* UberSignals.h */; settings = {ATTRIBUTES = (Public, ); }; };
72FED2121B2C97C400DCAB7E /* UberSignals.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 72FED2061B2C97C400DCAB7E /* UberSignals.framework */; };
72FED22B1B2C97D800DCAB7E /* UBSignal.h in Headers */ = {isa = PBXBuildFile; fileRef = 72FED2231B2C97D800DCAB7E /* UBSignal.h */; };
Expand Down Expand Up @@ -77,6 +84,10 @@
7249931B1C41DFFE006653CB /* UberSignals.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = UberSignals.framework; sourceTree = BUILT_PRODUCTS_DIR; };
724993241C41DFFE006653CB /* UberSignals tvOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UberSignals tvOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
724993371C41E021006653CB /* UberSignals.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = UberSignals.framework; sourceTree = BUILT_PRODUCTS_DIR; };
728AB04B1C7BA51600D13324 /* UberSignalsTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UberSignalsTests-Bridging-Header.h"; sourceTree = "<group>"; };
728AB04E1C7BA51600D13324 /* SwiftTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftTests.swift; sourceTree = "<group>"; };
72B48DF21C7E2A0200296268 /* UBBaseSignal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UBBaseSignal.h; sourceTree = "<group>"; };
72B48DF31C7E2A0200296268 /* UBBaseSignal.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UBBaseSignal.m; sourceTree = "<group>"; };
72F45D921B8C0F910025F83C /* UberSignals.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = UberSignals.podspec; sourceTree = "<group>"; };
72FED2061B2C97C400DCAB7E /* UberSignals.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = UberSignals.framework; sourceTree = BUILT_PRODUCTS_DIR; };
72FED20A1B2C97C400DCAB7E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -179,15 +190,17 @@
72FED2081B2C97C400DCAB7E /* UberSignals */ = {
isa = PBXGroup;
children = (
72FED2091B2C97C400DCAB7E /* Supporting Files */,
72B48DF21C7E2A0200296268 /* UBBaseSignal.h */,
72B48DF31C7E2A0200296268 /* UBBaseSignal.m */,
72FED20B1B2C97C400DCAB7E /* UberSignals.h */,
72FED2231B2C97D800DCAB7E /* UBSignal.h */,
72FED2241B2C97D800DCAB7E /* UBSignal.m */,
72FED2251B2C97D800DCAB7E /* UBSignal+Internal.h */,
72FED2261B2C97D800DCAB7E /* UBSignal+Preprocessor.h */,
72FED2271B2C97D800DCAB7E /* UBSignalObserver.h */,
72FED2281B2C97D800DCAB7E /* UBSignalObserver.m */,
72FED2291B2C97D800DCAB7E /* UBSignalObserver+Internal.h */,
72FED20B1B2C97C400DCAB7E /* UberSignals.h */,
72FED2091B2C97C400DCAB7E /* Supporting Files */,
);
path = UberSignals;
sourceTree = "<group>";
Expand All @@ -204,8 +217,10 @@
isa = PBXGroup;
children = (
72FED2371B2C97F200DCAB7E /* Helpers */,
72FED2321B2C97E500DCAB7E /* UBSignalTests.m */,
72FED2161B2C97C400DCAB7E /* Supporting Files */,
728AB04E1C7BA51600D13324 /* SwiftTests.swift */,
728AB04B1C7BA51600D13324 /* UberSignalsTests-Bridging-Header.h */,
72FED2321B2C97E500DCAB7E /* UBSignalTests.m */,
);
path = UberSignalsTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -275,6 +290,7 @@
72FED20C1B2C97C400DCAB7E /* UberSignals.h in Headers */,
72FED22D1B2C97D800DCAB7E /* UBSignal+Internal.h in Headers */,
72FED22E1B2C97D800DCAB7E /* UBSignal+Preprocessor.h in Headers */,
72B48DF41C7E2A0200296268 /* UBBaseSignal.h in Headers */,
72FED22F1B2C97D800DCAB7E /* UBSignalObserver.h in Headers */,
72FED2311B2C97D800DCAB7E /* UBSignalObserver+Internal.h in Headers */,
);
Expand Down Expand Up @@ -520,6 +536,7 @@
files = (
5EBEBDBC1C162E6600E8CA02 /* UBSignalObserver.m in Sources */,
5EBEBDB81C162E6600E8CA02 /* UBSignal.m in Sources */,
7219981D1C7E92C000551591 /* UBBaseSignal.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -529,13 +546,15 @@
files = (
7249934C1C41E1CE006653CB /* UBSignal.m in Sources */,
724993491C41E1C9006653CB /* UBSignalObserver.m in Sources */,
7219981E1C7E92C100551591 /* UBBaseSignal.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
724993201C41DFFE006653CB /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
728AB0511C7BA51600D13324 /* SwiftTests.swift in Sources */,
7249934E1C41E1E0006653CB /* UBSignalTests.m in Sources */,
7249934D1C41E1E0006653CB /* UBSignalEmitter.m in Sources */,
);
Expand All @@ -547,6 +566,7 @@
files = (
7249934B1C41E1CE006653CB /* UBSignal.m in Sources */,
7249934A1C41E1C9006653CB /* UBSignalObserver.m in Sources */,
7219981F1C7E92C100551591 /* UBBaseSignal.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -556,13 +576,15 @@
files = (
72FED2301B2C97D800DCAB7E /* UBSignalObserver.m in Sources */,
72FED22C1B2C97D800DCAB7E /* UBSignal.m in Sources */,
72B48DF51C7E2A0200296268 /* UBBaseSignal.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
72FED20D1B2C97C400DCAB7E /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
728AB04F1C7BA51600D13324 /* SwiftTests.swift in Sources */,
72FED2331B2C97E500DCAB7E /* UBSignalTests.m in Sources */,
72FED2361B2C97EB00DCAB7E /* UBSignalEmitter.m in Sources */,
);
Expand Down Expand Up @@ -683,24 +705,29 @@
7249932E1C41DFFE006653CB /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
INFOPLIST_FILE = UberSignalsTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.uber.UberSignals-tvOSTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_OBJC_BRIDGING_HEADER = "UberSignalsTests/UberSignalsTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Debug;
};
7249932F1C41DFFE006653CB /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = UberSignalsTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.uber.UberSignals-tvOSTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_OBJC_BRIDGING_HEADER = "UberSignalsTests/UberSignalsTests-Bridging-Header.h";
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Release;
Expand Down Expand Up @@ -872,6 +899,7 @@
72FED2201B2C97C400DCAB7E /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand All @@ -881,23 +909,28 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.ubercab.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = UberSignalsTests;
SDKROOT = iphoneos;
SWIFT_OBJC_BRIDGING_HEADER = "UberSignalsTests/UberSignalsTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
72FED2211B2C97C400DCAB7E /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = UberSignalsTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.ubercab.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = UberSignalsTests;
SDKROOT = iphoneos;
SWIFT_OBJC_BRIDGING_HEADER = "UberSignalsTests/UberSignalsTests-Bridging-Header.h";
};
name = Release;
};
B643B47A1C1EE50D00BE2A3B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
Expand All @@ -909,19 +942,23 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.ubercab.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "UberSignalsTests/UberSignalsTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
B643B47B1C1EE50D00BE2A3B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = UberSignalsTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.ubercab.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "UberSignalsTests/UberSignalsTests-Bridging-Header.h";
};
name = Release;
};
Expand All @@ -944,6 +981,7 @@
7249932D1C41DFFE006653CB /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
724993311C41DFFE006653CB /* Build configuration list for PBXNativeTarget "UberSignals tvOS Tests" */ = {
isa = XCConfigurationList;
Expand All @@ -952,6 +990,7 @@
7249932F1C41DFFE006653CB /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
7249933C1C41E021006653CB /* Build configuration list for PBXNativeTarget "UberSignals watchOS" */ = {
isa = XCConfigurationList;
Expand All @@ -960,6 +999,7 @@
7249933E1C41E021006653CB /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
72FED2001B2C97C400DCAB7E /* Build configuration list for PBXProject "UberSignals" */ = {
isa = XCConfigurationList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7249931A1C41DFFE006653CB"
BuildableName = "UberSignals tvOS.framework"
BuildableName = "UberSignals.framework"
BlueprintName = "UberSignals tvOS"
ReferencedContainer = "container:UberSignals.xcodeproj">
</BuildableReference>
Expand Down Expand Up @@ -44,7 +44,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7249931A1C41DFFE006653CB"
BuildableName = "UberSignals tvOS.framework"
BuildableName = "UberSignals.framework"
BlueprintName = "UberSignals tvOS"
ReferencedContainer = "container:UberSignals.xcodeproj">
</BuildableReference>
Expand All @@ -66,7 +66,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7249931A1C41DFFE006653CB"
BuildableName = "UberSignals tvOS.framework"
BuildableName = "UberSignals.framework"
BlueprintName = "UberSignals tvOS"
ReferencedContainer = "container:UberSignals.xcodeproj">
</BuildableReference>
Expand All @@ -84,7 +84,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7249931A1C41DFFE006653CB"
BuildableName = "UberSignals tvOS.framework"
BuildableName = "UberSignals.framework"
BlueprintName = "UberSignals tvOS"
ReferencedContainer = "container:UberSignals.xcodeproj">
</BuildableReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "724993361C41E021006653CB"
BuildableName = "UberSignals watchOS.framework"
BuildableName = "UberSignals.framework"
BlueprintName = "UberSignals watchOS"
ReferencedContainer = "container:UberSignals.xcodeproj">
</BuildableReference>
Expand Down Expand Up @@ -46,7 +46,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "724993361C41E021006653CB"
BuildableName = "UberSignals watchOS.framework"
BuildableName = "UberSignals.framework"
BlueprintName = "UberSignals watchOS"
ReferencedContainer = "container:UberSignals.xcodeproj">
</BuildableReference>
Expand All @@ -64,7 +64,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "724993361C41E021006653CB"
BuildableName = "UberSignals watchOS.framework"
BuildableName = "UberSignals.framework"
BlueprintName = "UberSignals watchOS"
ReferencedContainer = "container:UberSignals.xcodeproj">
</BuildableReference>
Expand Down
Loading

0 comments on commit 950bbff

Please sign in to comment.