[GH-ISSUE #415] Support for integration into Objective-C project for Swift 4.0 #267

Closed
opened 2026-03-03 16:47:13 +03:00 by kerem · 8 comments
Owner

Originally created by @gallymon on GitHub (Oct 23, 2017).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/415

Description: Help Wanted. I've been unable to get the Swift 4.0 version of this framework to integrate successfully with my Objective-C project.

I have, however, successful integrated the Swift 3.2 version of this framework.

In both cases, I add OAuthSwift to my project using cocoapod. For Swift 3.2, I use pod 'OAuthSwift', '~>1.1.2' and for Swift 4.0, I use pod 'OAuthSwift', '~>1.2.0' in my podfile.

In both cases, after the add, when I next fire up Xcode (9.0), it complains about encountering Swift 2.0 code so I go to targets > OAuthSwift > Build Settings > Basic > Swift Compiler Language and set both 'OAuthSwift' & 'Pods' columns to 3.2 or 4.0, as appropriate.

After this, I can build both projects (Swift 3.2 or 4.0) successfully. But note that I am not doing anything yet with OAuthSwift.

To try to use OAuthSwift, in one of my Objective-C .m files, I add the line @import OAuthSwift near the top.

Then, further down, in a method, I add the following code (which I gleaned from issue #269 ):

NSDictionary *parameters = @{ @"consumerKey": @"consumer_key",
                                                      @"consumerSecret": @"consumer_secret",
                                                      @"requestTokenUrl": @"request_token_url",
                                                      @"authorizeUrl": @"authorize_url",
                                                      @"accessTokenUrl": @"access_token_url"  };

OAuth1Swift *oauth = [[OAuth1Swift alloc] initWithParameters: parameters];

In the version of my project which has the Swift 3.2 version of OAuthSwift integrated into it, this code builds and the call to initWithParameters: parameters resolves.

In the version with Swift 4,.0, the call does not resolve and I get this:

No visible @interface for 'OAuth1Swift' declares the selector 'initWithParameters:'

I've been playing with this now for a day and I'm baffled where to go next - hence this issue report.

OAuth Provider (Twitter, Github, ..): GitHub

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

  • iOS :
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • CocoaPods
  • Manually

Library version:

  • head
  • v1.2 (Swift 4.0)
  • v1.0.0
  • v0.6
  • other: (Please fill in the version you are using.) 1.1.2

Xcode version:

  • 9.0 (Swift 4.0)

  • 9.0 (Swift 3.2)

  • 8.x (Swift 3.x)

  • 8.0 (Swift 2.3)

  • 7.3.1

  • other: (Please fill in the version you are using.)

  • objective c

Originally created by @gallymon on GitHub (Oct 23, 2017). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/415 ### Description: Help Wanted. I've been unable to get the Swift 4.0 version of this framework to integrate successfully with my Objective-C project. I have, however, successful integrated the Swift 3.2 version of this framework. In both cases, I add OAuthSwift to my project using cocoapod. For Swift 3.2, I use **pod 'OAuthSwift', '~>1.1.2'** and for Swift 4.0, I use **pod 'OAuthSwift', '~>1.2.0'** in my podfile. In both cases, after the add, when I next fire up Xcode (9.0), it complains about encountering Swift 2.0 code so I go to targets > OAuthSwift > Build Settings > Basic > Swift Compiler Language and set both 'OAuthSwift' & 'Pods' columns to 3.2 or 4.0, as appropriate. After this, I can build both projects (Swift 3.2 or 4.0) successfully. But note that I am not doing anything yet with OAuthSwift. To try to use OAuthSwift, in one of my Objective-C .m files, I add the line **@import OAuthSwift** near the top. Then, further down, in a method, I add the following code (which I gleaned from issue #269 ): ``` NSDictionary *parameters = @{ @"consumerKey": @"consumer_key", @"consumerSecret": @"consumer_secret", @"requestTokenUrl": @"request_token_url", @"authorizeUrl": @"authorize_url", @"accessTokenUrl": @"access_token_url" }; OAuth1Swift *oauth = [[OAuth1Swift alloc] initWithParameters: parameters]; ``` In the version of my project which has the Swift 3.2 version of OAuthSwift integrated into it, this code builds and the call to **initWithParameters: parameters** resolves. In the version with Swift 4,.0, the call does not resolve and I get this: **No visible @interface for 'OAuth1Swift' declares the selector 'initWithParameters:'** I've been playing with this now for a day and I'm baffled where to go next - hence this issue report. ### OAuth Provider (Twitter, Github, ..): GitHub ### OAuth Version: - [x] Version 1 - [x] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [x] CocoaPods - [ ] Manually ### Library version: - [ ] head - [x] v1.2 (Swift 4.0) - [ ] v1.0.0 - [ ] v0.6 - [x] other: (Please fill in the version you are using.) 1.1.2 ### Xcode version: - [x] 9.0 (Swift 4.0) - [x] 9.0 (Swift 3.2) - [ ] 8.x (Swift 3.x) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [ ] other: (Please fill in the version you are using.) - [x] objective c
kerem closed this issue 2026-03-03 16:47:13 +03:00
Author
Owner

@gallymon commented on GitHub (Oct 24, 2017):

A bit of addition information: I've taken a version of my Objective-C project and added OAuthSwift Library (using Swift 3.2) to it and generated a working version (as I described above).

Then I created another podfile and upgraded this project in-place from OAuthSwift (3.2) to (4.0). The upgraded version fails as I've described, above.

I get the feeling that there's something I need to do with Swift 4.0 to make it visible to Objective-C. Something that I did not have to do with Swift 3.2.

<!-- gh-comment-id:338832516 --> @gallymon commented on GitHub (Oct 24, 2017): A bit of addition information: I've taken a version of my Objective-C project and added OAuthSwift Library (using Swift 3.2) to it and generated a working version (as I described above). Then I created another podfile and upgraded this project in-place from OAuthSwift (3.2) to (4.0). The upgraded version fails as I've described, above. I get the feeling that there's something I need to do with Swift 4.0 to make it visible to Objective-C. Something that I did not have to do with Swift 3.2.
Author
Owner

@phimage commented on GitHub (Oct 24, 2017):

Have you a .swift-version file? With inside 4.0
Maybe try head instead of tagged version

If it could work, good thing , but I do not maintain compatibility with obj-c.

<!-- gh-comment-id:338944738 --> @phimage commented on GitHub (Oct 24, 2017): Have you a .swift-version file? With inside 4.0 Maybe try head instead of tagged version If it could work, good thing , but I do not maintain compatibility with obj-c.
Author
Owner

@gallymon commented on GitHub (Oct 25, 2017):

phimage,

I'm afraid I am in over my head here. This is my first occasion to try to include a Swift framework into my Objective-C project, my first time to use something from GitHub, my first time to use Cocoapds and, at this time, I have only a passing familiarity with Swift.

I've looked at a few OAuth libraries. Currently, I'm using STTwitter which is written in Objective-C but I think it is no longer in development and it seems Twitter specific. It looks like OAuthSwift is my best bet because it is generic (OAuth1 & OAuth2) and it is in active development.

For now, I think I'll stick with OAuthSwift 1.1.2 for Swift 3.2 which is working for me.

Maybe, as further work on the Swift 4.0 version of OAuthSwift occurs, someone will be able to take a look at why the Swift 3.2 version (1.1.2) integrates well with Objective_C whereas the Swift 4.0 version (1.2.0) does not.

I know at this point, my skills are no where near being able to sort this out.

Cheers, from New Zealand!

<!-- gh-comment-id:339504812 --> @gallymon commented on GitHub (Oct 25, 2017): phimage, I'm afraid I am in over my head here. This is my first occasion to try to include a Swift framework into my Objective-C project, my first time to use something from GitHub, my first time to use Cocoapds and, at this time, I have only a passing familiarity with Swift. I've looked at a few OAuth libraries. Currently, I'm using STTwitter which is written in Objective-C but I think it is no longer in development and it seems Twitter specific. It looks like OAuthSwift is my best bet because it is generic (OAuth1 & OAuth2) and it is in active development. For now, I think I'll stick with OAuthSwift 1.1.2 for Swift 3.2 which is working for me. Maybe, as further work on the Swift 4.0 version of OAuthSwift occurs, someone will be able to take a look at why the Swift 3.2 version (1.1.2) integrates well with Objective_C whereas the Swift 4.0 version (1.2.0) does not. I know at this point, my skills are no where near being able to sort this out. Cheers, from New Zealand!
Author
Owner

@gallymon commented on GitHub (Oct 25, 2017):

phimage,

Sorry, I should have also answered your specific questions and suggestions.

I can see the swift-version file in the GitHub listing of files. But here on my local system, I cannot find a swift-version file in either my swift 3.2 or swift 4.0 versions of OAuthSwift as integrated with my Objective-C project using cocoapods.

As far as trying to use cocoapod to install from 'head' rather than from a tagged version like 1.1.2, I confess to being a noobie and having no idea how to modify my podfile to do that.

Cheers!

<!-- gh-comment-id:339505718 --> @gallymon commented on GitHub (Oct 25, 2017): phimage, Sorry, I should have also answered your specific questions and suggestions. I can see the swift-version file in the GitHub listing of files. But here on my local system, I cannot find a swift-version file in either my swift 3.2 or swift 4.0 versions of OAuthSwift as integrated with my Objective-C project using cocoapods. As far as trying to use cocoapod to install from 'head' rather than from a tagged version like 1.1.2, I confess to being a noobie and having no idea how to modify my podfile to do that. Cheers!
Author
Owner

@phimage commented on GitHub (Oct 26, 2017):

Not a "swift+version" file but a ".swift-version" file, with a . so an hidden file in file system.

Sometimes cocoapod compile with the wrong version, so by putting a file at root of your project to indicate the version of swift you use could help


for cocoapod and head, just put the git after the pod 'OAuthSwift'
, :git => 'https://github.com/OAuthSwift/OAuthSwift.git' (then you can add a git commit, a branch a tag, see doc)


To be helped you can create a project with the issue but not your full code and commit it to github
So maybe I have time I will open it and see the issue.

<!-- gh-comment-id:339566548 --> @phimage commented on GitHub (Oct 26, 2017): Not a "swift+version" file but a ".swift-version" file, with a . so an hidden file in file system. Sometimes cocoapod compile with the wrong version, so by putting a file at root of your project to indicate the version of swift you use could help --- for cocoapod and head, just put the git after the pod 'OAuthSwift' , :git => 'https://github.com/OAuthSwift/OAuthSwift.git' (then you can add a git commit, a branch a tag, see doc) --- To be helped you can create a project with the issue but not your full code and commit it to github So maybe I have time I will open it and see the issue.
Author
Owner

@gallymon commented on GitHub (Oct 26, 2017):

phimage,

Many thanks for your willingness to help a noobie here. It is much appreciated. But, after wrestling with all this for several days, I think it is clear that I need to divide and conquer.

The best way, I think, to do that is to remove the complexity and confusion of trying to span from Objective-C, which I understand quite well, over to Swift, which I am still quite unfamiliar with. At every step, I am confronted with syntax and concepts which are new to me.

So, I think I'm going to go in search of an OAuth library written in Objective-C.

Cheers and best wishes from New Zealand!

<!-- gh-comment-id:339828959 --> @gallymon commented on GitHub (Oct 26, 2017): phimage, Many thanks for your willingness to help a noobie here. It is much appreciated. But, after wrestling with all this for several days, I think it is clear that I need to divide and conquer. The best way, I think, to do that is to remove the complexity and confusion of trying to span from Objective-C, which I understand quite well, over to Swift, which I am still quite unfamiliar with. At every step, I am confronted with syntax and concepts which are new to me. So, I think I'm going to go in search of an OAuth library written in Objective-C. Cheers and best wishes from New Zealand!
Author
Owner

@deberle commented on GitHub (Dec 29, 2017):

I am in the same situation as @gallymon
Are there any guides available to integrate OAuthSwift into an ObjC project?

<!-- gh-comment-id:354505473 --> @deberle commented on GitHub (Dec 29, 2017): I am in the same situation as @gallymon Are there any guides available to integrate OAuthSwift into an ObjC project?
Author
Owner

@phimage commented on GitHub (Jan 13, 2018):

@deberle sorry there is no guide

<!-- gh-comment-id:357476872 --> @phimage commented on GitHub (Jan 13, 2018): @deberle sorry there is no guide
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#267
No description provided.