How to integrate PayUMoney iOS SDK in swift project? - ios

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

Related

How do I create an Objective-C bridging header?

I'm following this guide on adding OneSignal to React Native, and there is one section where is says:
Open NotificationService.m or NotificationService.swift and replace the whole file contents with the code below:
<provides code to add>
If you are using Swift, make sure to create a separate Objective-C Bridging Header for your OneSignalNotificationExtensionService and add the following import:
#import "RCTOneSignalExtensionService.h"
Then you need to tell your Xcode project settings what your bridging header is named, like this.
I added the code they provided to NotificationService.swift because that's the only one of the two files that exists in my project. So I assume I'm "using swift" as they put it. The problem is that when they say to create a separate Objective-C Bridging Header, I don't know how to do that. All I've been able to find online is that when you import Objective-C code into your swift project, Xcode should automatically prompt you to create a bridging header. Xcode hasn't done that for me.
Does anyone know how I can create an Objective-C bridging header?
You have to create a new objective c class:
then
then you name it and specify as objective-c class at language
then you select your directory and hit create. At this point xcode is going to ask you whether or not you want to create bridging header. Yep do it.
And at the end it should look more or less like this at your project.
hope that helps you.

Objective-C Bridging Header section not found

I'm working on a React Native app and I'm trying to use a module called react-native-socketio.
In order to proceed with the app, I will need to bridge the objective C header in Xcode but the related section is missing.
According to the tutorial
I have also noticed that the section Swift Compiler – Code Generation is also missing from Xcode.
Why?
I have resolved this matter by first adding a new swift file to the project, then the respective section appeared.
As you can probably tell, I now have an empty Swift file just sitting inside my project folder and options to bridge my header file.
Thanks for the help everyone.
Looks like you have created an ObjectiveC project instead of Swift (I can see the AppDelegate.h & AppDelegate.m). ObjC project wont have Swift Compiler section. Select Swift as language while creating project

Converting objective-c frameworks and third party code to swift

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.

How to add Parse event recording to a custom iOS framework?

I want to add Parse.com event recording to my iOS app's custom framework. I have followed Parse's instructions, except I add the Parse and other required frameworks to my framework, rather than to my app. Everything is fine until I add the "import Parse" line to one of the files in my framework (the one I'm trying to add Parse to), at which point the compiler tells me "No such module 'Parse'". Cleaning and rebuilding (and trashing Derived Data, cleaning, and rebuilding) have the same result.
Thanks in advance.
Make sure that you create an objective-c bridging header (because of the tag, I'll assume you are programming in swift)
You can create a header by simply creating a new objective-c file and it will prompt you to create a new bridging header.
For more detailed instructions, see the following:
How to call Objective-C code from Swift
I managed to solve this problem and the solution is documented at https://gist.github.com/multinormal/206e72ec4bdd5990d4d8

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