Converting objective-c frameworks and third party code to swift - ios

I know those objective-c files must be converted to swift manually (with some help from several online converting tools),
the question is...
how about frameworks that're added to the project?
And third parties written in objective-c added via cocoapods?
Do I need to remove those frameworks, re-add third parties of their swift version, or let Xcode warn me with any possible error?
Maybe just keep them and add some bridge file to cope with those?
Need some information before I mess everything up...
Any link or file guide would be appreciated!

Obj-c frameworks can all be used in swift and will automatically be bridged to swift so you can access them from swift code (create an obj-c bridge, google it). You can add your own .h files to this obj-c bridge file too and use your obj-c code in swift. There's no need to search for swift libraries or anything.

Related

Publish my own CocoaPod Framework

I'm about to create a cocoaPod for a small iOS Framework for our customer. I have 2 questions about it.
1) I'm depending on another framework that is also available via cocoaPod. Could it happen that the original author removes the lib and therefor could kill my framework as well or is this secured?
2) I'm using Swift as the language of choice? Let's say one is importing an Obj-C Pod into a Swift project, he needs a bridging header. With the other way around, using a swift cocoapod with obj-c, does the user need to do anything to make this run?
Thanks
Yes, and hopefully the dependent framework doesn't remove his framework (its very rare they do it)
The bridging header is fine unless you use advanced generics (inheritance of a base generic class) as methods might not be available while converting to Objective-C.

How to integrate PayUMoney iOS SDK in swift project?

I'm developing an ecommerce iOS app in swift. I want to integrate PayUMoney iOS SDK into my project. Only Objective-C SDK is there. All SO questions, tutorials and documentations are in Objective-C only. Is there any way to integrate this SDK into swift project? Please help me.
To integrate Obj-C libraries into a Swift Project all you have to do is use a so-called Bridging Header. Those literally work as bridge between the Obj-C code and the Swift code. Here is an exact representation from the Apple Docs:
Basically what this does it let's Swift access everything through the one header file and for Obj-C it generates a .m file with all methods and other code.
To add a bridging header, simply create a new File -> iOS -> Source -> CocoaTouch -> UIViewcontroller and then as language select Objective-C. You can name it yourNewlyCreatedClass for example.
whatever you want as we'll later delete it.
Once you do that you will get this Pop Up:
asking you if you want to create the bridging header.
Select the create function and open the newly created file that should be named something like Briding-Header.h
Now, you can remove the line that say #import
"yourNewlyCreatedClass.h" and replace it with #import
<PayUMoney/PayUMoney.h> or whatever the framework is called.
To finish up, you can now delet the two created classes from before. Simply select yourNewlyCreatedClass.h and yourNewlyCreatedClass.m and you're good to go.
Congrats, now you can access any of the methods you see in their docs through simply typing them in your swift file.
For further reference, please advise the Apple Docs found here. Images were used from the official Apple Docs.
Hope that helps,
Julian

Building a Swift framework with references to Objective-C code

I'm working on an iOS project written in Swift, and I would like to take some classes out of the regular "app" project, and bundle it into a reusable Swift framework instead (and maybe make it publicly available on Github and via Cocoapods).
I'm running into issues because frameworks seemingly can't have Objective-C bridging headers, but in order to compile my framework code, I need to reference several Objective-C classes (in this case: the Google Maps iOS SDK).
I've also added GoogleMaps.framework as a linked library in my framework project, but then, how can I "import" it from Swift code?
Is this even possible with the current tools and Swift version, and how should I proceed?
Thanks.
It wasn't that complicated, actually... I was just doing some things wrong.
First, bridging headers are not required in that setting: the Google Maps iOS SDK is provided as a regular .framework file, so the development language has no impact on how it can be imported in Swift. Apple clearly mentions it in the documentation: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html, "Importing external frameworks".
It's as easy as adding the framework to the "Link binary with libraries" section of the project settings. Do not forget to also add depending libraries and frameworks (in GoogleMaps.framework's case, there are quite a few).
Then, in Swift code, the framework classes should be available simply by doing:
import GoogleMaps
No bridging header, no dealing with "non-modular header etc." errors.

Cocoapods - Hide implementation?

I have a iOS library that I created. Quite now I shipped this lib in a .framework file with only some .h files.
Now I would like to use Cocoapods instead of the framework.
Is it possible to hide the .m files and expose only some header files (like with the framework)?
According to this question I don't understand the relation between the podspec settings source_files and public_header_files.
I assumed that public_header_files would be my needed option, but I don't understand what this property is doing.
Edit:
I think I misunderstood the design of Cocoapods. public_header_files seems to make sense when using the use_framework! setting.
Maybe I'm trying Carthage instead.
For the Objective-C static framework, it is possible, you can try cocoapods-packager.
For Swift framework, so far it is impossible to use cocoapods-packager because of no volunteers. You can find the detailed information here:
But there is another way to Hide implementation of Swift framework when distributing it

Add MFSideMenu 3rd party library to swift project

I'm currently translating an Objective-C project I have over to Swift. In the process, I have a few implemented 3rd party libraries that are pure Objective-C like MFSideMenu and Parse.
I've created a Bridging-Header.h file per Apple's documentation and other's recommendations to bridge the Objective-C files with the Swift code. This works fine for frameworks like Parse. Unfortunately, when importing MFSideMenu and running the application, I receive the attached errors below.
I was contemplating if this was because a library needed to be manually imported into the Objective-C files using it, so I attempted importing UIKit and Foundation in the project and manually added the frameworks without any success. Any assistance would be greatly appreciated.
Turns out, the compiler for swift no longer supports non modular based imports for frameworks. You must change all references to frameworks to #import statements rather #import.
I had the same problem, add code below at the header file of this class
#import <UIKit/UIKit.h>
it can help you

Resources