I want to create an application core that connects to a webservice, downloads the data, parses it and then returns it to a view controller. This core would ideally handle requests from multiple controllers and abstract away a lot of repetitive code. Also, I want to potentially use this core for a mac os x application. Would these tasks be a good idea for a static library? Also, how do I add a static library to my iPhone App? Once the static library is added, how do I reference it (i.e. import statements, etc..)?
I want to create an application core that connects to a webservice, downloads the data, parses it and then returns it to a view controller. This core would ideally handle requests from multiple controllers and abstract away a lot of repetitive code. Also, I want to potentially use this core for a mac os x application. Would these tasks be a good idea for a static library?
Yes.
Also, how do I add a static library to my iPhone App?
Add the static library's target to your project, then add its build product to your iPhone app's target. When you start work on your Mac OS X app, add the library build product to that target as well.
Once the static library is added, how do I reference it (i.e. import statements, etc..)?
#import
is a preprocessor directive; you use it on a header file during the preprocessing stage of the compile-source-files phase.
Compiling the source files produces object files, which the linker will fuse (link) together in the next phase. This phase also includes the linker linking in any static libraries.
You must have the library build product (from the library target) added in the Link Binaries phase of the application target in order to have the linker link the library into your application.
There's no really good reason I can think of to create a static library unless you want to distribute it without distributing source. You have to re-compile for each platform, so you might as well just add the library .h and .m files from a common location (e.g. don't copy the file into the projects when adding them. The "Add Existing File..." selection will allow you to deselect the checkbox labeled "Copy items into destination group's folder (if needed)" when you add). Then, any changes you make to the library files will be updated in both projects. Building a static library just adds another layer of complexity (additional targets, etc.) that is unnecessary (IMHO, sorry to disagree Peter ;-) .
Best Regards.