How do I start a new Obj-C library project with Xcode? - objective-c

I am new to Xcode (and Objective C in general) and I want to create a new Objective-C Library (Framework?) which will be used by some of our iPhone applications in the future.
Which type of project should I choose when Xcode shows the new project dialog? I tried selecting "Blank Project" but then I faced some issues in defining the target, dependencies, etc.
I want my project to be easily re-usable in the future both in code form and as a .dylib.
I would appreciate some help with this. Links to online docs are welcome.

Since version 3 of the SDK you are able to create library projects in Xcode. However, those projects do not create .dylib libraries, but static .a libraries.
You cannot create Frameworks for iOS, as Apple's own App Store rules state that apps sold through the App Store cannot load code dynamically, which is what Frameworks are for. Libraries are designed to be statically linked.

Related

Can I import classes from an existing Objective C project into a Swift app

I have an existing app and I'd like to share a large number of classes from that app within a new app target. I'd like to leave the existing app as-is and treat it as a module (like a framework), importing it into the new app target which will be written in Swift.
Note this is NOT the simple documented case of adding Swift code to an existing Objective-C application target. I would like to see an example of using the module capability in Xcode to re-use code from an existing target in a new Swift target/module.
The existing app is built as an objective-C application (not a framework)
I would like to build a new app in Swift but use some of the non-gui code from the old app in the Swift app.
I have tried several times to see if there is a way I can import classes from the old iOS-objc app but I'm having difficulties using it in the new Swift app target, methods are not being found
I have turned on modules in this source app.
A) I would ideally like to import classes from the existing App target in the project without refactoring the original app.
B) If that is not possible I could potentially factor out the classes that are common into a separate objective-c framework. This I can get to work thanks to this (http://youtu.be/9us3uijFFpo) , but I'd like to see an example of A) if anyone can crack it. That use case is not covered in Apple's documentation.
But I've searched the web and I can't find any detailed examples of how to do this and my many various attempts to do so have been unsuccessful. There are plenty of references to adding Swift files into Obj-C apps, but nothing specifically about this kind of case.
You should read the chapter "Mix and Match" of this book from Apple:
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
It shows you how to import objective class to your swift project.
In general you have to do some steps:
add a "Bridging-Header.h" to your project with name: "YourProjectName-Bridging-Header.h"
Place your Obc headers somewhere then import ObjcClass.h to your project. I recommend to use "Link to file" instead of "Copy to
project"
In your bridging-header file, you add #import "ObjcClass.h" to import your ObjcClass header to your swift project
You may eventually have to specify Headers location in "Build Setting"

How can I distribute my objective c library with source code embedded

I would like for people to be able to debug my library, should they feel like they want to.
For this I think a good idea would be to embed the source in the library / framework itself. Does Xcode support this option?
For reference of what I’m looking for, in Java you can build a Jar file which comes with the attached source code (and optional javadoc) embedded within the library https://stackoverflow.com/a/5064833/48062
Xcode does not support this option, no. Your best bet would be to upload the source to Github (https://github.com) and include the link in your documentation for the framework. That way you can be sure that your users can always get to the freshest, most up to date, code.

Adding custom frameworks to Xcode frameworks list?

I have made a framework in Xcode. Each time I want to add it to another project, I need to look for it in its folder. Is there a way to add it to the frameworks list (like all the Apple frameworks) so that it's easier to add to a project?
Thanks.

Has anyone attempted to place compiled code in an NSBundle and load it at runtime? [duplicate]

As is known to everyone, static libraries can work well in an Iphone App and your App can be easily approved by IOS App Store
Unfortunately, the two static libraries I'm using now have the some C functions and variables.
so I compiled them into *.dylib (dynamic libraries), and copy them to "Bundle Resources" in XCode.
dylib_handle = dlopen(dylib_path_in_resource_bundle, RTLD_LAZY);
func = dlsym(dylib_handle, "func");
// invoke func();
This works well in simulator and Ipad (of course, different dynamic libraries).
I noticed that somebody said Iphone app does not support any third party dynamic libraries and my app will be rejected. (see here)
but I carefully read the "App Store Review Guidelines", I found no item meet my question.
I'm confused now!
Does iphone app support dynamic libraries? Does IOS AppStore allow this?
Who can give me an official response.
As Bernardo Ramos states in a comment: "Since iOS8 we can use dynamic libraries".
Dynamic libraries are not allowed by the App Store. No code may be loaded at run-time. The answer is to convert them to static libraries and compile them into the application.
From iPhoneOSTechOverview:
"If you want to integrate code from a framework or dynamic library into your application, you should link that code statically into your application’s executable file when building your project."
Read "should" as "must"
See SO Answer: Can create dynamic library for iOS?
No, dynamic libraries are not allowed.
But you can create static libraries, and even "static frameworks" (that is, like a classic framework is, a folder with the ".framework" extension and containing your Headers, resource files if any, and the lib itself, except that your lib must be a static library).

creating a reusable library in XCode 3.2

How do I create a reusable library/module in XCode 3.2? What I want to do is create a bunch of classes that provide certain functionality compile them into some kind of library, add such a library to an existing xcode project and use the classes in it.
I come from .NET world so what I want to do is basically to create an equivalent of 'assembly' and then reference it somehow in my XCode project.
I am developing for iOS btw.
If you add a target called static library you will get the equivalent of an assembly, just put all the sources in the target and decide what headers should be published and what should be hidden to the user of your library.
What you are looking to do is create a 'framework'.
This page has some useful information.
http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPFrameworks/Frameworks.html