سؤال

I'm working on an iOS app where I use third party libraries. I want to migrate my project to use ARC, but the third party libraries are still using the old memory management. So I want to separate third party code and put it in a separate project without ARC, and then somehow link that project into my iOS-app project, so that they will be built together using the same configuration.

Is this possible to do in a very simple way, or am i better of just turning off ARC for the individual files? (seems very tedious..)

Can I use a workspace? Where one project is my iOS app and the other just contains third party code?

I've played around a bit and googled a lot, but there just doesn't seem to be any simple soultion, or am I wrong?

هل كانت مفيدة؟

المحلول

So I figured it out myself, with a lot of help from different blogs. Something this basic should be more trivial and well documented... But here we go, this is what I did to get a library for AsiHttpRequest:

  1. Create a new iOS project. Select the 'Cocoa Touch Static Library' template. Call it whatever you like. You don't want to tick 'Use automatic reference counting', since AsiHttpRequest does not support it.
  2. Select a location for your library project (will matter later on).
  3. Delete the default .h- and .m-file created by Xcode.
  4. Drag and drop the AsiHttpRequest files into the project
  5. You can add the frameworks that AsiHttpRequest is dependent of, but you will have to add them to your main project anyway, so it is not necessary.
  6. Try to build the project, it should do so without errors.
  7. Open your main project
  8. From finder, drag your library .proj-file into your main project (in Xcode, so that it 'lands' onto the main project file)
  9. The library project should now appear under your main project (still in XCode). It should be expandable and you should be able to see the library project files as well. If it doesn't, try closing all open projects and reopen the main project.
  10. Select the main project, and select target. Under Build Phases - Link Binary With Libraries, click the +-sign.
  11. In the list of frameworks you should see your library project (called something like libname.a). Select that file
  12. The newly added file might appear red in the list of frameworks, don't worry, it works anyway. Guess it's a bug.
  13. Still under target, go to Build Settings
  14. Under Header Search Paths add the relative search path to where the library .h-files are. This is relative to your main projects .proj-file. (For example ../some folder/libproject/)
  15. Hopefully your main project will build without errors and the library project will be built at the same time, using the same configuration as the main project.

I have no idea if this is a good approach or if there is some easier way to do it. However, I like this, since I can use the library project in several projects. And if I want to update the library project, I only have to do it in one place, and the other projects will be updated as well, since they all reference the same project.

Edit1: I had some problems with library projects using objective c categories. I received unrecognized selector sent to instance errors in runtime when trying to call those methods. This problem was solved by following the answer given here.

  1. Go to build settings of the target in the main project and add -ObjC to the entry called Other Linker Flags

Edit2: I found this template for creating Universal frameworks. I haven't tried it, but I guess something like this would work as well.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top