简体   繁体   中英

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.

  1. 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.
  2. 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
  3. 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.
  4. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM