[GH-ISSUE #269] Support for integration into Objective-C project? #157

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

Originally created by @dfclark on GitHub (Aug 17, 2016).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/269

So far I've been unable to get this framework to integrate with an existing project written in Objective-C, either a standalone app or a framework that is consumed by that app. I add the OAuthSwift project to the target project, or I add the framework in via the Build Phases tab, and all seems as it should be, but "@import OAuthSwift" in an Objective-C class, or "import OAuthSwift" in a Swift class, results in the compiler reporting No such module" Could you provide any guidance?

Originally created by @dfclark on GitHub (Aug 17, 2016). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/269 So far I've been unable to get this framework to integrate with an existing project written in Objective-C, either a standalone app or a framework that is consumed by that app. I add the OAuthSwift project to the target project, or I add the framework in via the Build Phases tab, and all seems as it should be, but "@import OAuthSwift" in an Objective-C class, or "import OAuthSwift" in a Swift class, results in the compiler reporting No such module" Could you provide any guidance?
kerem 2026-03-03 16:46:13 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@phimage commented on GitHub (Aug 17, 2016):

Could you try with cocoapod or Carthage
I am not sure that you add the project correctly by reading the error message
Or there is elsewhere an other error message about OAuthSwift, a framework build issue

General guidance https://github.com/gergelyorosz/swift-objective-c-mixed-project

Maybe there is some code that cannot bé converted (generic enum...)

<!-- gh-comment-id:240526592 --> @phimage commented on GitHub (Aug 17, 2016): Could you try with cocoapod or Carthage I am not sure that you add the project correctly by reading the error message Or there is elsewhere an other error message about OAuthSwift, a framework build issue General guidance https://github.com/gergelyorosz/swift-objective-c-mixed-project Maybe there is some code that cannot bé converted (generic enum...)
Author
Owner

@dfclark commented on GitHub (Aug 17, 2016):

First I tried adding the OAuthSwift project as described in the README on the github page, and that didn’t work. So I built the framework using Carthage, added the resulting OAuthSwift.framework into the project (via the Build Phases page for the consuming project), and that didn’t work either.

Following the link you provided led to this bit on that page:
Invoking Swift code from Objective C

#import "MixedLanugageExample-Swift.h"

https://github.com/gergelyorosz/swift-objective-c-mixed-project#unit-testing-swift-classes-from-objective-c

This applies for accessing Swift code compiled in the project, and there is a chicken & egg problem with this too. Suppose I have a project named foo, and inside it I have a Swift class named bar. When I build the project, as long as nothing references bar yet, the bar declarations/definitions will be added to the foo-Swift.h file. The foo-Swift.h file is constructed down inside the build folder hierarchy, and must then be manually copied up to the project file so that it can be included in the foo project settings (and later checked into the VCS). If the build fails (perhaps because some code in foo is already referencing bar) the foo-Swift.h file won’t be built. Assuming that the header file was built, and copied to the project file, and referenced from the project settings, now Objective-C code in the foo project can reference bar, because now it’s defined. But that doesn’t apply to a framework that is incorporated into a project like foo – the framework is included, is not re-compiled, is not referenced in the foo-Swift file, and thus cannot be resolved by the compiler.

There must be a way to do this, but so far it has eluded me.

Thanks for the response.

From: Eric Marchand <notifications@github.commailto:notifications@github.com>
Reply-To: OAuthSwift/OAuthSwift <reply@reply.github.commailto:reply@reply.github.com>
Date: Wednesday, August 17, 2016 at 3:50 PM
To: OAuthSwift/OAuthSwift <OAuthSwift@noreply.github.commailto:OAuthSwift@noreply.github.com>
Cc: Don Clark <don_clark@onsetcomp.commailto:don_clark@onsetcomp.com>, Author <author@noreply.github.commailto:author@noreply.github.com>
Subject: [GRAYMAIL] Re: [OAuthSwift/OAuthSwift] Support for integration into Objective-C project? (#269)

Could you try with cocoapod or Carthage
I am not sure that you add the project correctly by reading the error message
Or there is elsewhere an other error message about OAuthSwift, a framework build issue

General guidance https://github.com/gergelyorosz/swift-objective-c-mixed-project

Maybe there is some code that cannot bé converted (generic enum...)


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHubhttps://github.com/OAuthSwift/OAuthSwift/issues/269#issuecomment-240526592, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJWcFcEgb2Hy2DF8suM96-3H8hTpv4p3ks5qg2YSgaJpZM4Jm0Fm.

<!-- gh-comment-id:240536797 --> @dfclark commented on GitHub (Aug 17, 2016): First I tried adding the OAuthSwift project as described in the README on the github page, and that didn’t work. So I built the framework using Carthage, added the resulting OAuthSwift.framework into the project (via the Build Phases page for the consuming project), and that didn’t work either. Following the link you provided led to this bit on that page: Invoking Swift code from Objective C - Import the XCode generated header filehttps://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html to use it in the .m file - E.g. in the MixedLanguageExample to use the ComponentSwift class from LabelObjectiveC: - Make sure for the main target, under Build Settings --> Defines Module is set to Yes - In LabelObjectiveC.m add #import "MixedLanugageExample-Swift.h" https://github.com/gergelyorosz/swift-objective-c-mixed-project#unit-testing-swift-classes-from-objective-c This applies for accessing Swift code compiled in the project, and there is a chicken & egg problem with this too. Suppose I have a project named foo, and inside it I have a Swift class named bar. When I build the project, as long as nothing references bar yet, the bar declarations/definitions will be added to the foo-Swift.h file. The foo-Swift.h file is constructed down inside the build folder hierarchy, and must then be manually copied up to the project file so that it can be included in the foo project settings (and later checked into the VCS). If the build fails (perhaps because some code in foo is already referencing bar) the foo-Swift.h file won’t be built. Assuming that the header file was built, and copied to the project file, and referenced from the project settings, now Objective-C code in the foo project can reference bar, because now it’s defined. But that doesn’t apply to a framework that is incorporated into a project like foo – the framework is included, is not re-compiled, is not referenced in the foo-Swift file, and thus cannot be resolved by the compiler. There must be a way to do this, but so far it has eluded me. Thanks for the response. From: Eric Marchand <notifications@github.com<mailto:notifications@github.com>> Reply-To: OAuthSwift/OAuthSwift <reply@reply.github.com<mailto:reply@reply.github.com>> Date: Wednesday, August 17, 2016 at 3:50 PM To: OAuthSwift/OAuthSwift <OAuthSwift@noreply.github.com<mailto:OAuthSwift@noreply.github.com>> Cc: Don Clark <don_clark@onsetcomp.com<mailto:don_clark@onsetcomp.com>>, Author <author@noreply.github.com<mailto:author@noreply.github.com>> Subject: [GRAYMAIL] Re: [OAuthSwift/OAuthSwift] Support for integration into Objective-C project? (#269) Could you try with cocoapod or Carthage I am not sure that you add the project correctly by reading the error message Or there is elsewhere an other error message about OAuthSwift, a framework build issue General guidance https://github.com/gergelyorosz/swift-objective-c-mixed-project Maybe there is some code that cannot bé converted (generic enum...) — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/OAuthSwift/OAuthSwift/issues/269#issuecomment-240526592, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJWcFcEgb2Hy2DF8suM96-3H8hTpv4p3ks5qg2YSgaJpZM4Jm0Fm.
Author
Owner

@phimage commented on GitHub (Aug 19, 2016):

I try with cocoapod
the framework has been compiled, header generated in the "Headers" folder of ios framework OAuthSwift-swift.h

In my objc class I add

#import "OAuthSwift-swift.h"

and test with

    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];
<!-- gh-comment-id:241031961 --> @phimage commented on GitHub (Aug 19, 2016): I try with cocoapod the framework has been compiled, header generated in the "Headers" folder of ios framework [OAuthSwift-swift.h](https://gist.github.com/phimage/9ffd5017c1df463a81b2edccb5595a9c) In my objc class I add ``` objc #import "OAuthSwift-swift.h" ``` and test with ``` objc 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]; ```
Author
Owner

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

I close because that's work for me (cocoapod tested only), feel free to open an other issue or comment this one (I will reopen it)

<!-- gh-comment-id:248863124 --> @phimage commented on GitHub (Sep 22, 2016): I close because that's work for me (cocoapod tested only), feel free to open an other issue or comment this one (I will reopen it)
Author
Owner

@smbhuin commented on GitHub (Nov 2, 2016):

authorize method not generating in objc in OAuthSwift class, so it completely useless in objc project.

<!-- gh-comment-id:257902001 --> @smbhuin commented on GitHub (Nov 2, 2016): authorize method not generating in objc in OAuthSwift class, so it completely useless in objc project.
Author
Owner

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

@5mb so you comment in closed issue... please see open issue

<!-- gh-comment-id:257904300 --> @phimage commented on GitHub (Nov 2, 2016): @5mb so you comment in closed issue... please see open issue
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#157
No description provided.