Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Swift bridging for RACSignalError using NS_ERROR_ENUM #150

Merged
merged 10 commits into from
Jan 7, 2019

Conversation

sharplet
Copy link
Contributor

Redefines RACSignalError using NS_ERROR_ENUM, allowing it to bridge to Swift as a new RACSignalError struct containing static instances of RACSignalError.Code, and allowing it to be used in error pattern matching contexts.

@sharplet
Copy link
Contributor Author

There’s a potential breaking change here: the symbols RACSignalErrorNoMatchingCase and RACSignalErrorTimedOut will no longer be available to Swift. I pushed commit 2334221, which adds them back in with a deprecated+renamed warning. Any thoughts on whether this is necessary? The downside is that it adds Swift code to a previously ObjC-only framework, which could cause build errors.

@sharplet
Copy link
Contributor Author

Discoved RACCommandErrorDomain and RACSelectorSignalErrorDomain and added bridging for those as well.

@sharplet
Copy link
Contributor Author

The pod lib lint failure appears to be a CocoaPods bug (CocoaPods/CocoaPods#8089):

 -> ReactiveObjC (3.1.0)
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | xcodebuild:  note: Planning build
    - NOTE  | xcodebuild:  note: Constructing build description
    - NOTE  | xcodebuild:  warning: Capabilities for App may not function correctly because its entitlements use a placeholder team ID. To resolve this, select a development team in the build settings editor. (in target 'App')
    - NOTE  | xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file. (in target 'App')
    - ERROR | [OSX] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.

Updating to CocoaPods 1.6.0.beta.2 locally resolved the error for me.

@sharplet
Copy link
Contributor Author

For some reason, switching to Apple TV 4K instead of Apple TV 1080p worked, even though Apple TV 1080p clearly seemed to be in the list of available destinations.

The CocoaPods thing is still there, but I’m comfortable ignoring it until 1.6.0 is released.

@@ -2579,13 +2600,19 @@
"DTRACE_PROBES_DISABLED=1",
);
INFOPLIST_FILE = ReactiveObjC/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be needed, I don't think. It should already be specified in the xcconfig?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this was probably an automatic Xcode change when adding the first Swift code to the target.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed all the redundant LD_RUNPATH_SEARCH_PATHS settings in commit 31e9f4a.

@@ -28,7 +28,7 @@ - (instancetype)initWithBlock:(id)block {
+ (id)invokeBlock:(id)block withArguments:(RACTuple *)arguments {
NSCParameterAssert(block != NULL);

RACBlockTrampoline *trampoline = [[self alloc] initWithBlock:block];
RACBlockTrampoline *trampoline = [(RACBlockTrampoline *)[self alloc] initWithBlock:block];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While debugging the pod lib lint failures on CI I noticed warnings like this:

- WARN  | [iOS] xcodebuild:  /Users/travis/build/ReactiveCocoa/ReactiveObjC/ReactiveObjC/RACBlockTrampoline.m:31:49: warning: 'initWithBlock:' is only available on iOS 10.0 or newer [-Wunguarded-availability]

This is a false positive, because it’s confusing our -[RACBlockTrampoline initWithBlock:] selector for something like -[NSThread initWithBlock:], which has only been available since iOS 10. Adding the explicit cast shouldn’t be necessary (this seems like a compiler/analyser bug), but it does remove the warning.

public let RACSignalErrorNoMatchingCase = RACSignalError.noMatchingCase.rawValue

@available(*, deprecated, renamed: "RACSignalError.timedOut")
public let RACSignalErrorTimedOut = RACSignalError.timedOut.rawValue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems great. 👏

PRODUCT_NAME = "$(PROJECT_NAME)Tests";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could potentially lower this version to 4.0 or even 3.0 to keep support for compiling with older Xcode versions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that's important.

@mdiep
Copy link
Contributor

mdiep commented Jan 6, 2019

This looks good once the pod lib lint is fixed.

@sharplet
Copy link
Contributor Author

sharplet commented Jan 7, 2019

@mdiep To fix it, we would either need to use a prerelease version of CocoaPods on CI or wait for 1.6.0 to land. With CocoaPods on a longer beta cycle, I’m not sure how long that will be.

Any preference?

@mdiep
Copy link
Contributor

mdiep commented Jan 7, 2019

I'm fine with that. 👍🏻 Merge at your leisure!

@sharplet
Copy link
Contributor Author

sharplet commented Jan 7, 2019

Oh weird, looks like I don’t have write access for ReactiveObjC?

Redefines `RACSignalError` using `NS_ERROR_ENUM`, allowing it to bridge
to Swift as a new `RACSignalError` struct containing static instances of
`RACSignalError.Code`, and allowing it to be used in error pattern
matching contexts.
This allows us to use CocoaPods 1.6.0.beta, which fixes a bug in
`pod lib lint` under Xcode 10.
@mdiep
Copy link
Contributor

mdiep commented Jan 7, 2019

Oh weird, looks like I don’t have write access for ReactiveObjC?

Just invited you to the right team for that!

@sharplet sharplet merged commit a621018 into ReactiveCocoa:master Jan 7, 2019
@sharplet sharplet deleted the as-swift-error-bridging branch January 7, 2019 20:58
@sharplet
Copy link
Contributor Author

sharplet commented Jan 7, 2019

@mdiep Thanks!

stuartofmine pushed a commit to stuartofmine/ReactiveObjC_2023 that referenced this pull request Oct 18, 2023
…dging

Support Swift bridging for RACSignalError using NS_ERROR_ENUM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants