I need to make a library with swift that support both swift and object c project (also support xcode 5), this will be a distribution library (do not share source code). There are two ways to do this: create a Cocoa Touch Framework or create a Cocoa Touch Static Library. I make some research, but still find out the solution. It seems the Cocoa Touch Framework not support to buid a distribution library, and I'm not sure the Cocoa Touch Static Library work perfect with with Swift yet or not. Any solutions for it. Thanks.
A very good example for this kind of library is Realm.
They both support swift and objective-c project integration. Check the repo on GitHub , and browse it : here
In fact, they have all the library coded in Objective-C, and the add Support for swift specifecity with extensions on objects used by the client. (For example, check the Realm/RLMSwiftSupport.m in their repo)
EDIT
To access a Swift class in Objective-C, just add #objc(MyClass) in your Swift Class and it will be available in Objective-C files.
Read the this for more informations about Objective-C and Swift working together
I faced the same issue as you to build one Pod library for both Swift and Objective-C, using pure code respectively without messing languages or include bridging headers. Actually I didn't try it by myself, but I came to several possible solutions:
1) To use a different branches of the same repo:
pod 'YourPodLib', :git => 'https://github.com/user_name/YourPodLib.git', :branch => 'objc'
pod 'YourPodLib', :git => 'https://github.com/user_name/YourPodLib.git', :branch => 'swift'
2) Experimenting with Subspecs as a way to install a subset of your library. (official cocoapods documentation: subspec )
It probably would look like:
pod 'YourPodLib/Swift'
Maybe my approach is far away from being ideal, but I would be appreciate if you correct me or suggest a better idea.
Related
I'm currently using Swift for an Objective-C project. Previously, I imported those Objective-C frameworks through bridging header since I did not use any Swift pods. But today, I need to use swift libraries such as Alamofire, which means I will need to use_framework! in my Pod File.
However, here comes the problem, after I pod install, and try to run the project on my device, errors jump up! What is even more odds is that everything works fine on simulator.
The errors are mainly about "Cannot find XX module" / "Cannot find XX local file" in objectiveC files.
I think it must have something to do with "use_frameworks" in cocoa pods. My question is how can I solve this problem? A million thanks beforehand, I have been scratching my head for this the whole day!
Go to Window -> Projects and Delete derived data. Then do a standard rebuild and it should work fine. I have run into this a few times when dealing with changing cocoapods.
My setup:
1) Cocoapod of Objective-C class installed in Swift 2.0 project works
2) If I attempt to import another Objective-C class, the addition of a bridging header seems to break the class imported by the Cocoapod.
I have an Cocoapod written in Objective-C I've successfully imported into a Swift 2.0 project. Everything works fine with that Cocoapod. I didn't have to do anything to get it to work--it just "worked".
When I attempt to import another Objective-C class into my project WITHOUT Cocoapods, the addition of the bridging header seems to break my previously imported Cocoapod. The moment I create a bridging header, my project stops seeing the original Cocoapod's classes.
I suspect the new bridging header is breaking something the Cocoapod set up, but I'm unable to find another bridging header in my project. If anyone has suggestions where to look for the issue, I would be grateful for them.
Update
I tried adding the 2nd non-Cocoapod Objective-C class WITHOUT adding a bridging header at the prompt and I get same error. No such module 'CocoaPodClassThatWorkedBefore'
I have no idea why or how this worked, but I went to the command line in my project's directory and reinstalled the Cocoapod using the following:
pod install
I had already installed the Cocoapod, but after adding another non-Cocoapod Objective-C class to a Swift 2.0 project, something got fouled up. Reinstalling the Cocoapod seems to have resolved the issue of Xcode not seeing the original installation.
For those who aren't familiar with Git or Github, I strongly suggest you learn it and have it implemented on your project before attempting this solution. Alternatively, have a clean backup of your project laying around in case it doesn't go according to plan.
I have a npapi plugin(bundle) for chrome, which use C++ and objective-c. now it needs to be build by google native client.
I wonder that can nacl support objective-c? how to compile o-c file by MakeFile
And if possible, how to build nacl plugin in Xcode? I tried, but i found that the libraries of nacl are " archive with no architecture specification".(use lipo -info *.a)
I hope someone to help me, thanks a lot!!!
If you use Objective-C without any of its usual libraries then you should be able to use the PNaCl toolchain (which is based on LLVM) to have it parse Objective-C. I'm not aware of projects that have done this, so you should definitely let folks on the mailing list know if you get something working (do keep the questions on SO, though!).
It sounds like your application won't be running on the open web (where only architecture-independent PNaCl can run, not NaCl), so you could either use the PNaCl toolchain to create a .pexe, or you could use the same toolchain to create a .nexe for each architecture you target. The documentation I linked to helps with both approaches, but note that using the PNaCl toolchain to create a .nexe is currently being improved. You can therefore follow the instructions on the bug tracker, or try out nacl-clang when it's released (or build it yourself if you're brave).
There are a ton of libraries/pieces of code that have already been built in Objective-C can RubyMotion use these bits without rewriting them in Ruby?
There are a couple ways to do this. One is by vendoring your 3rd party code into the vendor directory and then using the app.vendor_project method in your Rakefile. See Using 3rd Party Libraries for an example.
Another option is using Cocoapods. With the motion-cocoapods Ruby gem, you can add any of the libraries here using something like this:
app.pods do
dependency 'JSONKit'
end
I've been reading about how to create a new plugin for Phonegap and seems to get it by following this tutorial.
http://wiki.phonegap.com/w/page/36753496/How%20to%20Create%20a%20PhoneGap%20Plugin%20for%20iOS
However, I'm having a hard time grasping how to extend an existing plugin. (not creating a new one)
Been reading this tutorial.
http://hiediutley.com/2011/03/28/phonegap-tutorial-series-3-extending-the-phonegap-api/
I can't seem to get where I can possibly add line of codes to the .m file for example. In my XCode, I only see the .h files but not the .m file.
Or is there a better way to extend an api?
Thank you,
Tee
EDIT: This answer is no longer completely correct.
The latest versions of Cordova / PhoneGap do not come as a compiled framework and it is much easier (especially since 2.2.0) to tweak the version of cordova a particular app uses as it is simply a sub-project in XCode.
To get at the .m files you would have to download the PhoneGap (Cordova) iOS source and make your changes them compile your own version of the PhoneGap framework.
That is not as hard as it sounds, but can be a bit daunting if you are not super comfortable with Objective-C and command line compilation tools.
To paraphrase the README from the iOS source, for example:
$ git clone http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios.git
Make your changes, then...
Launch "Terminal.app"
Navigate to the folder where the Makefile is (./PhoneGapLib ?)
Type in make then press Enter
This should build "PhoneGapInstaller.dmg" into the dist folder. This is what you use to install your new version of PhoneGap.
Another option is to take the .m and .h files of the API you are extending (by simply getting them from the GitHub source repository) and making them into a new plugin with your own name. As an example, rather than extend the Camera API and make changes to Camera.m and recompile etc... I chose to make a plugin unoriginally called MyCamera that had the code from the Camera API and my own extensions. Most of the APIs in PhoneGap (at least in iOS) are basically already plugins in their own right, so they don't need much tweaking to be turned into a plugin just for your purposes.
This method also means you can upgrade PhoneGap later and not clobber all your extensions.