Using CHDataStructures.framework on iPhone - iphone

I'm new to iPhone programming and I'm trying to use CHDataStructures in my project. But I'm running into some issues:
When I directly try to build it right after download I get the error "Foundation/Foundation.h" no such file or directory. The Active SDK is "Use Base SDK" and the active architecture is x86_64. I believe I should set the Active SDK to the iPhone SDK but it isn't listed there;
At some point (I don't remember how) I managed to tweak it and I got the iPhone SDK (simulator) in the active SDK but when I tried to build it I got the following error: "target specifies product type 'com.apple.product-type.framework', but there's no such product type for the 'iphonesimulator' platform";
And now I'm stuck. What am I doing wrong?
Thanks in advance,
Nuno

CHDataStructures is a framework that was written for the Mac. Frameworks are not used on the iPhone, static libraries are employed in their place. I'd suggest creating a new Cocoa Touch Static Library project, then adding all of the source files to that static library. None of the source files for the project appear to include Cocoa.h or other Mac-specific headers, so you should be able to get this static library to compile without too much fiddling.
There are several good questions on creating and using static libraries here, including the following:
"Implementing Static Libraries In iPhone"
"How SHOULD you make (and use) static libraries on the iPhone"
"Creating static library for iPhone"
For examples of static libraries out there, I'd direct you to the Three20 and Core Plot projects.
UPDATE: CHDataStructures now supports both a Mac framework and iOS static library.

Related

How to build dynamic lib for iOS with XCode 4.3.2

I am trying to build a dynamic library for iOS 5, but there is no template for this. Can you help me please?
There are no user dynamic library for iOS, at least none that are officially supported. Indeed, an iOS app (which Apple would accept in its App Store) must me comprised of a single binary file (plus resources). This means that you can only link static libraries with your main program.
The iOS SDK supports the creation of native applications that appear on the device’s Home screen only. It does not support the creation of other types of code, such as drivers, frameworks, or dynamic libraries. 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.
(source - "What can you create?" section)
Of course, dynamic linking is supported by iOS; it is only that Apple does not support its use in iOS apps, except for SDK frameworks.
If you are interested in creating a dynamic library anyhow, have a look at this article. The trick is starting with a plain Cocoa (i.e., MacOS) framework bundle, then change the build settings in order to compile against the iOS SDK.

can I use dynamic library(shared object) in my iphone app?

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).

Difference between static and dynamic library in Xcode for iPhone

What is the difference between a static and dynamic library in XCode? And why doesn't Apple allow us to use dynamic libraries in our iOS applications?
While you can build dynamic libraries for Mac OS X, you cannot use them for iPhone development.
A static library is merely an archive of object files that gets pulled into a program linking against it. The linker will unarchive all the archive files, and pull them in during linking along with the rest of your object files.
A dynamic library however, creates a shared object file, akin to a program but without an entry point, which programs can link against and call out of themselves into these shared libraries for their symbols, without pulling them into itself.
A dynamic library wouldn't make any sense for an iphone app as there is no way to install the library on the phone. I remember reading some documentation where apple stated they decided not to use dynamic libraries as they didn't want users to have to deal with hassles of finding/updating libraries. Much easier to just install 1 bundle per app.
Apple does allow you to make dynamic libraries. On Mac OS X, these end in .bundle or .dylib (not .so or .a like on Linux).
What, specifically are you trying to do? Did you create a target for your dylib?
iOS static vs dynamic library
Static library(.a) - library which copies all it's content into a target at compile time. That is why compile time is slower and result file is bigger, but there is no delay in run time
Dynamic library(.dylib) - library which has a single copy in a system where linking happens during run time. That is why compile time is faster, footprint of output file is smaller but there are some delays in runtime. Dynamic library is prerogative of OS(a lot of system libraries are dynamic) and as a developer you are not able to create it. Since such type of library is shared between different applications it should be secure and support IPC
Dynamic framework - framework with Dynamic library inside. Apple presented Dynamic framework and App extension[About] from iOS v8. You are able to use it inside single application to share common code and resources inside app sandbox
[Vocabulary]

C Binary/Source Code in an iPhone XCode Project

What's the best practice to include existing C Libraries into an iPhone Project? I searched the Internet and actually found some pieces but nothing that explains the exact way to do it.
I'm trying to include the following Citrix XenServer SDK Library.
Any help is appreciated. Thanks!
You could try to build a static library and link against that.
I didn't try that myself yet, but as far as I could see, libxenserver has libxml2 as its only dependency.
libxml2 is available on the iPhone so you might have a chance.
To get started, create a Cocoa touch static library project and drag the C files into the project.
Now you have to figure out where to place the include files.
This might get a bit tricky and you will start with a lot of compile errors, but to me it seems possible to get it compiled.
The way I did it was to just create an iPhone static library project in Xcode and drop all the library's files in there. Then check if it builds and if the build settings are appropriate for the library you wish to compile. To add the newly-created library to your binary, you should follow the steps explained in the bottom part of the Three20 readme.
Note that you can only add static libraries to iPhone projects if you wish to get them into the App Store. Xcode also doesn't provide means to create dynamic iPhone libraries.

Can I develop my own objective-C Framework for Cocoa Touch Applications?

Is it possible to create an own obj-C Cocoa Touch framework which can be used by other developers? And furthermore can you protect this framework?
I've created templates for Xcode 4 that allow you to build universal iOS frameworks (which work in both device and simulator).
Once the templates are installed, you simply select "Static iOS Framework" when creating a new project and it does the rest. It also works with unit tests.
https://github.com/kstenerud/iOS-Universal-Framework
You can create a static library. There is an option in the XCode project chooser to do this. You'll have to distribute the compiled static library file and the header files to users of your library. Your actual implementation files (.m) do not need to be distributed.
GHUnit does a good job of this - packaging up the libraries for both simulator and device - so I recommend looking at this project. (I also recommend using this library for unit testing :-)
The frameworks in Objective C are typically just C / ObjC code and a bunch of classes, nothing amazingly special. As such, you can create your own if you'd like, and then just include that in your project when you build it. The iPhone doesn't care about the difference, it just knows to put all that code into your app, along with everything else.
Have a look at the Framework Programming Guide on Apple's website. It will get you started. Essentially what you'll do is create a Framework project in XCode and then go from there.
As for "protecting" your framework, I assume you mean making your code unreadable. I'm not sure if and how you can do this, but perhaps Apple's guide will say something about it.
Yes you can create frameworks for use with Cocoa Touch.
However there are these caveats:
has to be a statically linked libary, no dynamic loading (dyld) for us
should be a combined (lipo) library for i386 (simulator), arm6 and arm7
you need to hack a bundle project into a framework
you should embed (small and few) images into the library so that the developer does not have to mess around with resources but just drags/drops it into his project
... or if you have large and many images build a bundle with these
I have guides for these things on my site.
1+2 = http://www.drobnik.com/touch/2010/04/universal-static-libraries/
The other links you have to google because this site does not let me post more than one URL.
You could make a static library available as binary (i.e. rudimentary "protection") to third parties, but not a dynamic one, as Apple's App Store policy prevents dynamic linking.
Take a look at a worked example for static libraries given at
this site
If you're going to do it, in my opinion JSON.framework is a great example to follow. To hide/obfuscate the source code is a different story, and a different question entirely,
When creating a new project, navigate to iOS > Framework & Library > Cocoa Touch Framework, it's as simple as that. When you are successfully compile, .framework will be created under Products folder in XCode. Right click to show in Finder, and you can find the output.
It's unlikely this will work the way you want it to because the other developers won't be able to use your framework. This StackOverflow Question explains why.