1

I'm new to Objective-C but has a lot experience with Java and .NET.

I'm trying to add EGOPhotoViewer to my iOS 5 project in Xcode 4.2.1. But I get a lot of release, dealloc, retain etc. issues while compiling their code, since I'm using Automatic Reference Counting (I think!).

How can I create a class library, framework or what it is called in Objective C for their code, that I can add to my project?

EDIT: I've done the approach from JeremyP by inserting the code with a new target. I compiled in the beginning, but after a while I get this compile error:

Undefined symbols for architecture i386:
  "_OBJC_METACLASS_$_EGOPhotoViewController", referenced from:
      _OBJC_METACLASS_$_PhotoViewController in PhotoViewController.o
  "_OBJC_CLASS_$_EGOPhotoViewController", referenced from:
      _OBJC_CLASS_$_PhotoViewController in PhotoViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Does anybody know why?

dhrm
  • 14,335
  • 34
  • 117
  • 183

4 Answers4

9

For your purpose, a regular static library as described by beryllium would do fine.

Just for unashamed plug purposes and for spreading the word, this document describes how to create versioned, documented frameworks using Xcode, GIT and DoxyGen.

Creating a Versioned Framework 1.23

The main purpose of creating such frameworks is to redistribute them. I personally find it extremely annoying to manually include libraries and headers I receive from third parties - especially if the libraries are delivered in separate versions for simulator and device. That guide is meant for classic middleware developers. I have written it to allow people like those folks from Google Analytics to finally provide something worth their brand.

This document gives you a step by step explanation, bundled with loads of screenshots.

Till
  • 27,559
  • 13
  • 88
  • 122
  • do you still have that document for creating a framework? I imagine a lot has changed, since 2011, but it might still be relevant. – Sheamus Mar 22 '18 at 04:42
3

Open Xcode -> File -> New -> New Project -> Framework & Library -> Next -> Type Name, Choose Folder -> Create

It will be a library called yourApp.a. You can find it in Derived Data folder

beryllium
  • 29,669
  • 15
  • 106
  • 125
  • That would be a static library - not a framework - but that is how this is commonly done. For details on creating a proper framework, see my answer... – Till Dec 01 '11 at 15:05
  • Yes, this is a library as i mentioned at the end of the my post. – beryllium Dec 01 '11 at 15:08
  • What is the Derived Data folder? I've created the new project and I'm currently trying to see it I can compile it. When it is compiled, how can I added it to my other project where I need it? – dhrm Dec 01 '11 at 15:16
  • There are no files in your project! Only `EGO-Prefix.pch`! – beryllium Dec 01 '11 at 15:24
  • Sorry, I uploaded the wrong project. Please download my static library from here: http://uploads.demaweb.dk/EGO.zip. Can you compile it? Maybe I've taken the wrong files from their code. – dhrm Dec 01 '11 at 15:28
  • You need to write #import , UIKit, QuartCore and other frmaeworks yourself, there are no precompiled headers. – beryllium Dec 01 '11 at 15:50
  • I got it working by using the approach by Jeremy, but it should be very similar. Would you please check the edit I did in my question above? – dhrm Dec 01 '11 at 16:32
1

You can't create frameworks for iOS. You can however, create static libraries using beryllium's technique. You can also add a static library to your existing project using File / New / New Target... Obviously, once you create the target you can change the Objective-C automatic reference counting build setting to "no" for your new target.

I thought it was possible to turn ARC on and off at the source file level, but I can't figure out how.

JeremyP
  • 84,577
  • 15
  • 123
  • 161
  • @Till: That's not technically a framework though. It's actually a bundle that packages a static library and its headers and documentation. That's not meant as a criticism, it looks like a great idea. – JeremyP Dec 02 '11 at 14:32
  • @JeremyP I am not sure if that is really the case or not. Technically speaking it is exactly what you describe. The only difference to those frameworks that Apple provides us with is the fact that the libraries are static and not dynamic. – Till Dec 03 '11 at 00:30
  • @Till: I think we are just arguing semantics here. To my mind, a framework in the technical OS X sense (iOS is a version of OS X) is a bundle containing headers and a **dynamically** linked library. It doesn't alter the usefulness of your idea, which I think is great. – JeremyP Dec 05 '11 at 08:57
  • see also this answer: http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project – Lance May 17 '12 at 20:07
0

I've created frameworks on multiple occasions using the following method:

http://db-in.com/blog/2011/07/universal-framework-iphone-ios-2-0/

Sanjay Chaudhry
  • 3,181
  • 1
  • 22
  • 31
  • I've tried to follow this guide, but I get some errors when I try to build the aggregator. You can see my small example project here: http://uploads.demaweb.dk/EGO-framework.zip. I hope you can tell me what is wrong. Thanks! – dhrm Dec 01 '11 at 19:04