[GH-ISSUE #280] XCode8 + Cocoapods 1.1.0.rc.2 + objective-c based #164

Closed
opened 2026-03-03 16:46:16 +03:00 by kerem · 21 comments
Owner

Originally created by @ikbenben on GitHub (Sep 26, 2016).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/280

Hi there,

I'm having trouble building our project after upgrading to XCode8 and Cocoapods 1.1.0.rc.2. Our project is objective-c based and everything was working fine until today. Basically I'm seeing 76 errors in the Pod when it tries to build it.

We are currently importing OAuthSwift using @import OAuthSwift statement. I've tried to switch that to #import "OAuthSwift-swift.h" but there issues are still there. Kind of makes sense as it isn't actually able to build the pod.

A lot of the issues appear to be related to syntax error which leads me to believe it is something to do with Swift 3 or 2.3 updates. I'm not up on Swift yet but an example error is "Expected 'let' in conditional"

Our Podfile.lock file shows that we are using OAuthSwift 0.6.0

Any ideas?

Originally created by @ikbenben on GitHub (Sep 26, 2016). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/280 Hi there, I'm having trouble building our project after upgrading to XCode8 and Cocoapods 1.1.0.rc.2. Our project is objective-c based and everything was working fine until today. Basically I'm seeing 76 errors in the Pod when it tries to build it. We are currently importing OAuthSwift using @import OAuthSwift statement. I've tried to switch that to #import "OAuthSwift-swift.h" but there issues are still there. Kind of makes sense as it isn't actually able to build the pod. A lot of the issues appear to be related to syntax error which leads me to believe it is something to do with Swift 3 or 2.3 updates. I'm not up on Swift yet but an example error is "Expected 'let' in conditional" Our Podfile.lock file shows that we are using OAuthSwift 0.6.0 Any ideas?
kerem 2026-03-03 16:46:16 +03:00
Author
Owner

@phimage commented on GitHub (Sep 26, 2016):

please check if you really use 0.6.0 (28 Jul )
and not last commit of master branch (use swift 3 but not yet released)

I will create a swift 2.2 branch now

<!-- gh-comment-id:249724803 --> @phimage commented on GitHub (Sep 26, 2016): please check if you really use 0.6.0 (28 Jul ) and not last commit of master branch (use swift 3 but not yet released) I will create a swift 2.2 branch now
Author
Owner

@ikbenben commented on GitHub (Sep 27, 2016):

Hi @phimage

My Podfile only specifies the pod nae 'OAuthSwift' so I can only assume that it is the commit specified in the pod repository at Cocoapods.

pod 'OAuthSwift'

I'm not sure a 2.2 branch helps. XCode 8 expect Swift 2.3 or Swift 3. I saw that there were 2.3 and 3.0 branches in your repository after creating this issue so I was going to update my Podfile to point to one of those and try again. I assume Pods can reference a repo/branch instead of a version

<!-- gh-comment-id:249788044 --> @ikbenben commented on GitHub (Sep 27, 2016): Hi @phimage My Podfile only specifies the pod nae 'OAuthSwift' so I can only assume that it is the commit specified in the pod repository at Cocoapods. ``` pod 'OAuthSwift' ``` I'm not sure a 2.2 branch helps. XCode 8 expect Swift 2.3 or Swift 3. I saw that there were 2.3 and 3.0 branches in your repository after creating this issue so I was going to update my Podfile to point to one of those and try again. I assume Pods can reference a repo/branch instead of a version
Author
Owner

@phimage commented on GitHub (Sep 27, 2016):

yes if you use XCode8 you must choose one branch
you can try swift 2.3 branch
or point to master by specifying the git link (not released yet)

<!-- gh-comment-id:249788489 --> @phimage commented on GitHub (Sep 27, 2016): yes if you use XCode8 you must choose one branch you can try swift 2.3 branch or point to master by specifying the git link (not released yet)
Author
Owner

@ikbenben commented on GitHub (Sep 27, 2016):

Hi @phimage that seemed to sort it out. I pointed to the swift 3.0 branch

thanks

<!-- gh-comment-id:249809121 --> @ikbenben commented on GitHub (Sep 27, 2016): Hi @phimage that seemed to sort it out. I pointed to the swift 3.0 branch thanks
Author
Owner

@phimage commented on GitHub (Sep 27, 2016):

the swift 3.0 branch is just a "fast" and temporary xcode conversion, master branch have more commit but I don't know its status about compatibility with objective c (due to function renaming)
anyway when OAuthSwift 1.0.0 will be released you will have the last master code branch

<!-- gh-comment-id:249810875 --> @phimage commented on GitHub (Sep 27, 2016): the swift 3.0 branch is just a "fast" and temporary xcode conversion, master branch have more commit but I don't know its status about compatibility with objective c (due to function renaming) anyway when OAuthSwift 1.0.0 will be released you will have the last master code branch
Author
Owner

@ikbenben commented on GitHub (Oct 9, 2016):

Hi @phimage ,
You seem to have deleted the swift3.0 branch but now I seem to be stuck again. If I point to the swift2.3 branch, the version reverts to 0.6 and I get a lot of compile errors. If I use master, I don't get any compile errors but the authorizeWithCallback:scope:state:params:headers:success:failure: method is not available or any similar method signatures

any ideas how to proceed?

thanks

<!-- gh-comment-id:252507046 --> @ikbenben commented on GitHub (Oct 9, 2016): Hi @phimage , You seem to have deleted the swift3.0 branch but now I seem to be stuck again. If I point to the swift2.3 branch, the version reverts to 0.6 and I get a lot of compile errors. If I use master, I don't get any compile errors but the authorizeWithCallback:scope:state:params:headers:success:failure: method is not available or any similar method signatures any ideas how to proceed? thanks
Author
Owner

@phimage commented on GitHub (Oct 9, 2016):

The function has been renamed to follow Swift 3 rules see release note : authorize(withCall...

But I don't know the result using obj c.

Maybe a swift-version file is missing for Swift 2.3 branch. (I think cocoapod use this file to choose Swift version)

<!-- gh-comment-id:252510266 --> @phimage commented on GitHub (Oct 9, 2016): The function has been renamed to follow Swift 3 rules see release note : authorize(withCall... But I don't know the result using obj c. Maybe a swift-version file is missing for Swift 2.3 branch. (I think cocoapod use this file to choose Swift version)
Author
Owner

@ikbenben commented on GitHub (Oct 9, 2016):

So any suggestions on how I can proceed?

<!-- gh-comment-id:252510627 --> @ikbenben commented on GitHub (Oct 9, 2016): So any suggestions on how I can proceed?
Author
Owner

@phimage commented on GitHub (Oct 9, 2016):

I have checked the swift2.3 branch, there is the swift-version file
I create an obc project and add a podfile

    pod 'OAuthSwift', :git =>  'https://github.com/OAuthSwift/OAuthSwift.git',  :branch => 'swift2.3'

maybe try to clean derived data, builds folders
or go to the pod project into your workspace, click OAuthSwift target, then build settings and look for "Use legacy swift language version"
for 2.3 => Yes , for 3.0 => No

<!-- gh-comment-id:252512502 --> @phimage commented on GitHub (Oct 9, 2016): I have checked the swift2.3 branch, there is the swift-version file I create an obc project and add a podfile ``` ruby pod 'OAuthSwift', :git => 'https://github.com/OAuthSwift/OAuthSwift.git', :branch => 'swift2.3' ``` maybe try to clean derived data, builds folders or go to the pod project into your workspace, click OAuthSwift target, then build settings and look for "Use legacy swift language version" for 2.3 => Yes , for 3.0 => No
Author
Owner

@phimage commented on GitHub (Oct 9, 2016):

as information it seems that swift3 branch doesn't expose some functions to objective c

SWIFT_CLASS("_TtC10OAuthSwift10OAuthSwift")
@interface OAuthSwift : NSObject
@property (nonatomic, strong) OAuthSwiftClient * _Nonnull client;
@property (nonatomic, strong) id <OAuthSwiftURLHandlerType> _Nonnull authorizeURLHandler;
+ (void)handleWithUrl:(NSURL * _Nonnull)url;
SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, strong) NSNotificationCenter * _Nonnull notificationCenter;)
+ (NSNotificationCenter * _Nonnull)notificationCenter;
SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, strong) NSOperationQueue * _Nonnull notificationQueue;)
+ (NSOperationQueue * _Nonnull)notificationQueue;
- (void)removeCallbackNotificationObserver;
- (void)cancel;
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
@end


SWIFT_CLASS("_TtC10OAuthSwift11OAuth1Swift")
@interface OAuth1Swift : OAuthSwift
@property (nonatomic) BOOL allowMissingOAuthVerifier;
- (nonnull instancetype)initWithConsumerKey:(NSString * _Nonnull)consumerKey consumerSecret:(NSString * _Nonnull)consumerSecret requestTokenUrl:(NSString * _Nonnull)requestTokenUrl authorizeUrl:(NSString * _Nonnull)authorizeUrl accessTokenUrl:(NSString * _Nonnull)accessTokenUrl OBJC_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithParameters:(NSDictionary<NSString *, NSString *> * _Nonnull)parameters;
@property (nonatomic, readonly, copy) NSDictionary<NSString *, NSString *> * _Nonnull parameters;
@end


SWIFT_CLASS("_TtC10OAuthSwift11OAuth2Swift")
@interface OAuth2Swift : OAuthSwift
@property (nonatomic) BOOL accessTokenBasicAuthentification;
@property (nonatomic) BOOL allowMissingStateCheck;
- (nonnull instancetype)initWithConsumerKey:(NSString * _Nonnull)consumerKey consumerSecret:(NSString * _Nonnull)consumerSecret authorizeUrl:(NSString * _Nonnull)authorizeUrl accessTokenUrl:(NSString * _Nonnull)accessTokenUrl responseType:(NSString * _Nonnull)responseType;
- (nonnull instancetype)initWithConsumerKey:(NSString * _Nonnull)consumerKey consumerSecret:(NSString * _Nonnull)consumerSecret authorizeUrl:(NSString * _Nonnull)authorizeUrl accessTokenUrl:(NSString * _Nonnull)accessTokenUrl responseType:(NSString * _Nonnull)responseType contentType:(NSString * _Nonnull)contentType;
- (nonnull instancetype)initWithConsumerKey:(NSString * _Nonnull)consumerKey consumerSecret:(NSString * _Nonnull)consumerSecret authorizeUrl:(NSString * _Nonnull)authorizeUrl responseType:(NSString * _Nonnull)responseType OBJC_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithParameters:(NSDictionary<NSString *, NSString *> * _Nonnull)parameters;
@property (nonatomic, readonly, copy) NSDictionary<NSString *, NSString *> * _Nonnull parameters;
@end

it's a little weird...because there is no "@noobjc" annotation. but maybe I understand why
I create two function with same signature for objective c

func authorize(withCallbackURL callbackURL: URL, success: @escaping TokenSuccessHandler, failure: FailureHandler?) -> OAuthSwiftRequestHandle? {

func authorize(withCallbackURL urlString: String, success: @escaping TokenSuccessHandler, failure: FailureHandler?) -> OAuthSwiftRequestHandle? {

maybe if I rename the second one authorize(withCallbackURLString, this will work...

<!-- gh-comment-id:252513246 --> @phimage commented on GitHub (Oct 9, 2016): as information it seems that swift3 branch doesn't expose some functions to objective c ``` objc SWIFT_CLASS("_TtC10OAuthSwift10OAuthSwift") @interface OAuthSwift : NSObject @property (nonatomic, strong) OAuthSwiftClient * _Nonnull client; @property (nonatomic, strong) id <OAuthSwiftURLHandlerType> _Nonnull authorizeURLHandler; + (void)handleWithUrl:(NSURL * _Nonnull)url; SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, strong) NSNotificationCenter * _Nonnull notificationCenter;) + (NSNotificationCenter * _Nonnull)notificationCenter; SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, strong) NSOperationQueue * _Nonnull notificationQueue;) + (NSOperationQueue * _Nonnull)notificationQueue; - (void)removeCallbackNotificationObserver; - (void)cancel; - (nonnull instancetype)init SWIFT_UNAVAILABLE; @end SWIFT_CLASS("_TtC10OAuthSwift11OAuth1Swift") @interface OAuth1Swift : OAuthSwift @property (nonatomic) BOOL allowMissingOAuthVerifier; - (nonnull instancetype)initWithConsumerKey:(NSString * _Nonnull)consumerKey consumerSecret:(NSString * _Nonnull)consumerSecret requestTokenUrl:(NSString * _Nonnull)requestTokenUrl authorizeUrl:(NSString * _Nonnull)authorizeUrl accessTokenUrl:(NSString * _Nonnull)accessTokenUrl OBJC_DESIGNATED_INITIALIZER; - (nullable instancetype)initWithParameters:(NSDictionary<NSString *, NSString *> * _Nonnull)parameters; @property (nonatomic, readonly, copy) NSDictionary<NSString *, NSString *> * _Nonnull parameters; @end SWIFT_CLASS("_TtC10OAuthSwift11OAuth2Swift") @interface OAuth2Swift : OAuthSwift @property (nonatomic) BOOL accessTokenBasicAuthentification; @property (nonatomic) BOOL allowMissingStateCheck; - (nonnull instancetype)initWithConsumerKey:(NSString * _Nonnull)consumerKey consumerSecret:(NSString * _Nonnull)consumerSecret authorizeUrl:(NSString * _Nonnull)authorizeUrl accessTokenUrl:(NSString * _Nonnull)accessTokenUrl responseType:(NSString * _Nonnull)responseType; - (nonnull instancetype)initWithConsumerKey:(NSString * _Nonnull)consumerKey consumerSecret:(NSString * _Nonnull)consumerSecret authorizeUrl:(NSString * _Nonnull)authorizeUrl accessTokenUrl:(NSString * _Nonnull)accessTokenUrl responseType:(NSString * _Nonnull)responseType contentType:(NSString * _Nonnull)contentType; - (nonnull instancetype)initWithConsumerKey:(NSString * _Nonnull)consumerKey consumerSecret:(NSString * _Nonnull)consumerSecret authorizeUrl:(NSString * _Nonnull)authorizeUrl responseType:(NSString * _Nonnull)responseType OBJC_DESIGNATED_INITIALIZER; - (nullable instancetype)initWithParameters:(NSDictionary<NSString *, NSString *> * _Nonnull)parameters; @property (nonatomic, readonly, copy) NSDictionary<NSString *, NSString *> * _Nonnull parameters; @end ``` it's a little weird...because there is no "@noobjc" annotation. but maybe I understand why I create two function with same signature for objective c ``` func authorize(withCallbackURL callbackURL: URL, success: @escaping TokenSuccessHandler, failure: FailureHandler?) -> OAuthSwiftRequestHandle? { func authorize(withCallbackURL urlString: String, success: @escaping TokenSuccessHandler, failure: FailureHandler?) -> OAuthSwiftRequestHandle? { ``` maybe if I rename the second one `authorize(withCallbackURLString`, this will work...
Author
Owner

@ikbenben commented on GitHub (Oct 9, 2016):

I think that would solve it. Methods with same signature but different types are not allowed in a lot of languages. I'm surprised it's ok in swift. Can you create a branch and I'll try it tomorrow morning.. It's late here in Amsterdam :)

<!-- gh-comment-id:252516701 --> @ikbenben commented on GitHub (Oct 9, 2016): I think that would solve it. Methods with same signature but different types are not allowed in a lot of languages. I'm surprised it's ok in swift. Can you create a branch and I'll try it tomorrow morning.. It's late here in Amsterdam :)
Author
Owner

@phimage commented on GitHub (Oct 9, 2016):

same time here in paris :p
swift3.0objc branch created, you can test it ("Use legacy swift language version" => No in target build settings if many errors)

<!-- gh-comment-id:252518107 --> @phimage commented on GitHub (Oct 9, 2016): same time here in paris :p swift3.0objc branch created, you can test it ("Use legacy swift language version" => No in target build settings if many errors)
Author
Owner

@ikbenben commented on GitHub (Oct 10, 2016):

Good morning @phimage

I'm still not getting any love. I can see you changed the signature but its still not picking it up. I think the bridging doesn't understand the authorize(withCallbackURL syntax

Any chance we can try an old syntax like authorizeWithCallbackURL. Maybe this is a method that just passes to the authorize(withCallbackURL method?

I've tried to use the 2.3 branch again and get a lot of errors in the library itself. I've taken a screenshot and put it up at https://drive.google.com/file/d/0B1JerioCGxaKRExjN3czN2wzanM/view?usp=sharing

It fails if I try to convert the 2.3 branch

btw, you mention 'Use legacy swift language version' in the build settings but I don't have this setting anywhere

<!-- gh-comment-id:252554309 --> @ikbenben commented on GitHub (Oct 10, 2016): Good morning @phimage I'm still not getting any love. I can see you changed the signature but its still not picking it up. I think the bridging doesn't understand the authorize(withCallbackURL syntax Any chance we can try an old syntax like authorizeWithCallbackURL. Maybe this is a method that just passes to the authorize(withCallbackURL method? I've tried to use the 2.3 branch again and get a lot of errors in the library itself. I've taken a screenshot and put it up at https://drive.google.com/file/d/0B1JerioCGxaKRExjN3czN2wzanM/view?usp=sharing It fails if I try to convert the 2.3 branch btw, you mention 'Use legacy swift language version' in the build settings but I don't have this setting anywhere
Author
Owner

@phimage commented on GitHub (Oct 10, 2016):

If you use cocoapod you have this settings
In workspace created by cocoadpod you must have a "Pods" project (in Finder, under Yourproject/Pods/Pods.xcodeproj)
In this project you must have one target by framework imported, and OAuthSwift must be there

I find why the function is not shown. The failure handler contain typed OAuthSwiftError that cannot be converted to NSError
Without that, swift will ask me to add the @noobjc annotation because of the two functions authorize(withCallbackURL

I add an objc_authorize... function to test

<!-- gh-comment-id:252559014 --> @phimage commented on GitHub (Oct 10, 2016): If you use cocoapod you have this settings In workspace created by cocoadpod you must have a "Pods" project (in Finder, under Yourproject/Pods/Pods.xcodeproj) In this project you must have one target by framework imported, and OAuthSwift must be there I find why the function is not shown. The failure handler contain typed `OAuthSwiftError` that cannot be converted to `NSError` Without that, swift will ask me to add the @noobjc annotation because of the two functions `authorize(withCallbackURL` I add an objc_authorize... function to test
Author
Owner

@phimage commented on GitHub (Oct 10, 2016):

I implement CustomNSError protocol but any change
I see an other issue with the return type OAuthSwiftRequestHandle(I will add an annotation @objc)
I make a new swift3.0objc branch and test that

<!-- gh-comment-id:252565850 --> @phimage commented on GitHub (Oct 10, 2016): I implement `CustomNSError` protocol but any change I see an other issue with the return type `OAuthSwiftRequestHandle`(I will add an annotation @objc) I make a new swift3.0objc branch and test that
Author
Owner

@ikbenben commented on GitHub (Oct 10, 2016):

k. should I just hold off and wait for your go ahead?

<!-- gh-comment-id:252567345 --> @ikbenben commented on GitHub (Oct 10, 2016): k. should I just hold off and wait for your go ahead?
Author
Owner

@phimage commented on GitHub (Oct 10, 2016):

So in swift3.0objc I add prefixed function with bridge_ (bridge_authorizeWithCallbackURL)
that take a string as URL
You can go with that, but you cannot use "client" functions... In Bridge.swift you must add to fix that all functions : "bridge_get", "bridge_post", etc... (I have no more time)

There is again a problem with "OAuthSwiftHTTPRequest.Method : String" that is not bridged to objc (need NSString maybe but I thinks that's an other swift/objc bridging issue in compilator)

So to resume :

  • failure callback with OAuthSwiftError is not bridged (temporary solution = callback with Error). The OAuthSwiftError could be objective-c compatible if declare a raw type (ex: OAuthSwiftError: Int, Error) but enum with raw type could not have arguments (errors, messages, ...)
  • OAuthSwiftHTTPRequest.Methodis not bridged (put NSString instead of String or create each method "bridge_get", "bridge_post")
  • function naming conflict: two functions with same signature but different type will not be bridged (rename to withCallbackURLString or maybe add an annotation on one function @nonobjc)
<!-- gh-comment-id:252569782 --> @phimage commented on GitHub (Oct 10, 2016): So in swift3.0objc I add prefixed function with `bridge_` (`bridge_authorizeWithCallbackURL`) that take a string as URL You can go with that, but you cannot use "client" functions... In Bridge.swift you must add to fix that all functions : "bridge_get", "bridge_post", etc... (I have no more time) There is again a problem with "OAuthSwiftHTTPRequest.Method : String" that is not bridged to objc (need NSString maybe but I thinks that's an other swift/objc bridging issue in compilator) So to resume : - failure callback with `OAuthSwiftError` is not bridged (temporary solution = callback with `Error`). The `OAuthSwiftError` could be objective-c compatible if declare a raw type (ex: `OAuthSwiftError: Int, Error`) but enum with raw type could not have arguments (errors, messages, ...) - `OAuthSwiftHTTPRequest.Method`is not bridged (put NSString instead of String or create each method "bridge_get", "bridge_post") - function naming conflict: two functions with same signature but different type will not be bridged (rename to withCallbackURLString or maybe add an annotation on one function @nonobjc)
Author
Owner

@ikbenben commented on GitHub (Oct 10, 2016):

I've given it a try and we have LOVE!! :) Thanks for the getting this to work so quickly.

One note, the generate methods didn't include parameter names. I had to manually add the parameter names but no big deal

Not sure if I should close the ticket or if you intend to tidy things up so we can remove the swift3.0obj branch in the future

<!-- gh-comment-id:252576731 --> @ikbenben commented on GitHub (Oct 10, 2016): I've given it a try and we have LOVE!! :) Thanks for the getting this to work so quickly. One note, the generate methods didn't include parameter names. I had to manually add the parameter names but no big deal Not sure if I should close the ticket or if you intend to tidy things up so we can remove the swift3.0obj branch in the future
Author
Owner

@phimage commented on GitHub (Oct 10, 2016):

I will try to do better so let's open this issue

I don't want to maintain objc branch
I want to keep compatibility with objc but use swift with its full potential (ie. typed error)

so maybe

  • I will add some preprocessor macros (to force use of Error instead of OAuthSwiftError)
  • or add Bridge.swift in main branch (maybe optional with cocoapod subspec)
<!-- gh-comment-id:252698173 --> @phimage commented on GitHub (Oct 10, 2016): I will try to do better so let's open this issue I don't want to maintain objc branch I want to keep compatibility with objc but use swift with its full potential (ie. typed error) so maybe - I will add some preprocessor macros (to force use of Error instead of OAuthSwiftError) - or add Bridge.swift in main branch (maybe optional with cocoapod subspec)
Author
Owner

@phimage commented on GitHub (Nov 5, 2016):

next version (1.1.0 in master branch), soon released
functions will be prefixed with objc_ instead of bridge

580c85fecc

<!-- gh-comment-id:258623183 --> @phimage commented on GitHub (Nov 5, 2016): next version (1.1.0 in master branch), soon released functions will be prefixed with objc_ instead of bridge 580c85feccaec3b924347fb28c1cad82911f8828
Author
Owner

@ikbenben commented on GitHub (Nov 5, 2016):

Thanks @phimage . I'll review and update the project

<!-- gh-comment-id:258623905 --> @ikbenben commented on GitHub (Nov 5, 2016): Thanks @phimage . I'll review and update the project
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#164
No description provided.