Thrift framework for iPhone - iphone

I'm currently stuck trying to get my objective c generated files to compile in my iPhone project. Basically it keeps telling me there is no such directory for the following four imports:
Thrift/TProtocol.h
Thrift/TApplicationException.h
Thrift/TProtocolUtil.h
Thrift/TProcessor.h
I'm following all the instructions on the Thrift wiki and have downloaded and compiled the Thrift framework in XCode but there is no information specific to iPhone development. I'm almost certain it's a problem specific to an iPhone project because if I create a new command line project in XCode, I can import those files just fine.

After retaining the services of some kind of sorcerer I have figured out how to get Thrift to work with the iPhone/iPad (or at least get it to compile okay).
First, you want to grab the objective-c files with this command instead of from the wiki:
svn co http://svn.apache.org/repos/asf/incubator/thrift/trunk/lib/cocoa/src/ thrift-cocoa
Then, make a new Xcode project by going to New Project, selecting Framework & Library and Cocoa Framework. Click create and save it somewhere nice. Right click on Targets and select Add -> New Target. Choose Cocoa Touch and then Static Library. Give it a nice name. Go to the target's Build tab in info and change the Base SDK to iPhone Device (I'm using 3.2 but you can use whatever) and change Architectures to either Standard (armv6 armv7) or Optimized (armv7). Under the General tab add the Foundation and Cocoa frameworks.
Drag all of the files and folders you got from the svn repository into the Classes folder in the project. Check the copy items box and check the boxes next to both targets. Remove TSocketServer.h and .m from the Static Library's Copy Headers and Compile Sources folders respectively. You can now build the Static Library (and Framework optionally).
Open the project you want to use Thrift in and go to your target's General tab in info. Add the Static Library you just created to the Linked Libraries list. It should be named libYOUR_TARGET_NAME.a. Under the build tab go to Header Search Paths and add the path to the Thrift project you just created and check the recursive box.
Finally you just need to change the import statements in the Thrift generated code by simply removing the brackets and replacing them with quotes. You can now build you iPhone project again.

Try adding those .h files to your Xcode project.

Related

Externally added frameworks are not copied when project is copied in xcode

I have added external frameworks from my mac's Documents folder into my project.
Now when I copy this project to someother place and compile them I m getting errors .Its becoz those frameworks are not copied.Those frameworks appear to be in red colur in Frameworks group.
How can I make all the custom added frameworks to be copied when the project is copied to a newer place?
Add these framework first of all under build phases in link binary with libraries means drag & drop these framework there first & then try to add in another place.try it.

Installing Core-Plot in Xcode 4.2 for iOS project

I am trying to install Core Plot into my iOS app. I have followed the instructions on the Core Plot website but they are very brief and have no screenshots. I have pasted the instructions below and explained where I am stuck...
First, drag the CorePlot-CocoaTouch.xcodeproj file into your iPhone
application's Xcode project. Show the project navigator in the
left-hand list and click on your project.
Select your application target from under the "Targets" source list
that appears. Click on the "Build Phases" tab and expand the "Target
Dependencies" group. Click on the plus button, select the
CorePlot-CocoaTouch library, and click Add. This should ensure that
the Core Plot library will be built with your application.
Done!
Core Plot is built as a static library for iPhone, so you'll need to
drag the libCorePlot-CocoaTouch.a static library from under the
CorePlot-CocoaTouch.xcodeproj group to the "Link Binaries With
Libraries" group within the application target's "Build Phases" group
you were just in.
Done!
You'll also need to point to the right header location. Under your
Build settings, set the Header Search Paths to the relative path from
your application to the framework/ subdirectory within the Core Plot
source tree. Make sure to make this header search path recursive. You
need to add -ObjC to Other Linker Flags as well (as of Xcode 4.2,
-all_load does not seem to be needed, but it may be required for older Xcode versions).
I dont understand this bit!
Core Plot is based on Core Animation, so if you haven't already, add
the QuartzCore framework to your application project.
Done!
Finally, you should be able to import all of the Core Plot classes and
data types by inserting the following line in the appropriate source
files within your project:
#import "CorePlot-CocoaTouch.h"
Done!
Is anyone able to put the instruction I am struggling with into more laymans terms?
Seeing as how I wrote those instructions, I can take a stab at clarifying the part you're having trouble with.
You'll need to set the header search path so that when you include CorePlot-CocoaTouch.h, Xcode knows where to pull that from. This is located within the Build Settings for your application project under the Header Search Paths build setting. It looks like the following:
Double-click on the field for the header search paths and bring up this popup:
The path you specify here is the relative path from your Xcode project file to the directory where you installed Core Plot. In my case, I had both my application project directory and Core Plot located within the same ~/Development directory, so the relative path involved stepping back a level (the ../) and going to the core-plot directory that I had cloned the framework into. You then need to point to the framework subdirectory, where the actual framework source is stored.
Finally, checking the little box to the left of the path makes the header search recursive, so it will find headers contained in subdirectories of this one.
As far as the linker flags go, find your Other Linker Flags within these same Build Settings and add -ObjC to the list of linker flags:
This is needed so that symbols from the categories we use in the static library get pulled into your project properly. As I indicate, we used to need to add -all_load to this as well to work around a linker bug, but LLVM in Xcode 4.2 fixes this. That's good, because -all_load sometimes introduced duplicate symbols and broke building against certain third-party frameworks.
Hopefully, this should clear up that particular section of the instructions. I tried to do my best to make those easy to follow and keep them up to date with the latest Xcode versions, but perhaps I wasn't detailed enough. If you got through all the rest of the steps fine, you should be good to go.
The easiest way is to include the core-plot .h files and the library binary files (the .a file).
You just drag them all into the project.
Cheers.

how do I reference a separate project in xcode 4?

How do I reference another project which has code I wish to leverage in XCode 4. In particular I'm trying to make use of the NSDate extensions from here.
Some notes:
I was assuming I should probably reference rather than trying build a framework
I tried copying the existing "Hello World" xcode project file across into my project, however this didn't seem to work
Do I need to create a new "Target" based on "coco touch static library" option?
Then would I need to Edit the current Product Scheme so that when I build the new target would build
What do I need to do on my project side exactly - should going Add Files, and choosing the extensions Xcode Project File be enough?
thanks
I was assuming I should probably reference rather than trying build a framework
yes, reference and link with it, unless you need only a bit of it. at this stage, separating the bits you want may be an advanced topic (depends on the lib's layout/depends as well). you should prefer to reference and link because it will normally minimize your maintenance time, especially if you use it in multiple projects.
I tried copying the existing "Hello World" xcode project file across into my project, however this didn't seem to work
you don't create a project, you add the library's xcode project to your app or library, set the lib as a dependency, add the library to your search paths if needed, then link with the library.
Do I need to create a new "Target" based on "coco touch static library" option?
no
Then would I need to Edit the current Product Scheme so that when I build the new target would build
no. you configure it as a dependency. you may need to alter the lib's build settings if there is a major conflict, which the linker or compiler would point out.
What do I need to do on my project side exactly - should going Add Files, and choosing the extensions Xcode Project File be enough?
start with the process outlined above.
There is no reason to bring in an actually project. Either you can bring in the source files themselves and you could even use the same exact files instead of copying them if you want. However, if you have more than just a few files, and you don't think you will be changing the code much, then creating a static library would probably be the best option.

Can you reference Xib files from static libraries on the iPhone?

In my app, i currently have all my code separated into a static library, to make it easier to set up the xcode project targets for the actual app and for unit tests for my code. The problem with this is that i want to put most of my xib files in the static library as well, but it seems that when i run my app and try to reference the xib it can't find it unless it is included in the actual app's target instead of the static library target. Is it possible to have xib files and other resources included in static libraries that can be referenced by code in that same library, and if so, how?
No it isn't possible, because a static library is not the same as a "bundle".
A bundle is a directory that may contain all manner of files including resource files (xib), executable files and static libraries. It exists on the filesystem as a group of individual files.
A static library is a single file that contains classes, code and variables that were linked together by the library creator. It does not "contain" other files, it is essentially a database of compiled code.
Although it would be possible to put the data for the xibs in there, Xcode would have no way of knowing that it was in there, as it looks for them as individual files on the filesystem.
In Mac OS, you may create a "Framework" which is essentially a bundle of code, resources, settings etc which may be reused by multiple projects. However, Apple does not seem to support custom framework creation for iPhone OS.
Bundles
https://developer.apple.com/library/content/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW1
Static Libraries
http://en.wikipedia.org/wiki/Static_library
Reply to comment (won't fit in comment box)
No worries, I've been trying to do pretty much the same thing as you for the last week - I'd like to ship a "framework" of xibs, include files and .a libs to a client without giving them all the source code. I couldn't find a good way to do this with bundles either.
For whatever reason, Apple are being particularly obtuse about this - I can't see a reason for them to be so in the case of static libraries (dynamic libraries fair enough).
My solution for now is to manually create a package folder "Foo" that contains the following subfolders:
"include" -> put .h files here
"res" -> put .xib files here
"lib" -> contains "iphoneos" & "iphonesimulator" subfolders each with libFoo.a
Then zip this up and send to the client. The client then:
Unzips the package where ever they like.
Adds the "res" folder under the resources group.
Changes the following target settings:
Other Linker Flags = -Objc -lfoo
Header Search Paths = /include
Library Search Paths = /lib/$(PLATFORM_NAME)
I can probably automate the package creation with some build steps at my end, but the client is stuck with four slightly fiddly steps to get set up.
I found a perfect solution for this that does all the above automatically and more
https://github.com/kstenerud/iOS-Universal-Framework
Its an xCode plugin
It worked for me like a charm,
It works only for XCode 4 and above
Yes You can. add a xib file in your library as you would do for any normal project. Then in library project target add the xib file in copy Files section along with .a file.
In your main project where you are using the library, drag and drop the xib file where .a file for library is located.
Answer in including Xib files to your static library.
This time we have Xcode 11, you just create a bundle target in addition to your library target. The bundle template is available on macOS. Then from the library code, reference the bundle to be able to reference the nib. You distribute the library with the bundle.
A detailed video about using Xibs with static libraries below:
https://www.youtube.com/watch?v=WQI02KR9kQw
When distributing you could also create an SDK. JSON.framework did this in their SVN, and I successfully replicated this. You can see how this was done in http://hltypes.svn.sf.net/ in the hltypes-ios.xcodeproj and the iOS folder in the project.
Primarily you need to "install" into your build folder, and then you need to copy the specially formatted SDKSettings.plist. Then add the path to the SDK into "Additional SDKs" list in application project. Downside of composite SDKs are the need to restart Xcode 3.x whenever this mini-SDK is updated, and Xcode's insistence on constructing a composite SDK created from Apple's base SDK and your mini-SDK (which means you need to wait quite a bit).
Application project still needs to have .xib and other resources manually added.

How do I create a bundle of reusable code in Xcode?

I am developing an iPhone app and have to parse xml files in order to put them into a database. I will also be using those same xml parsers in my app so users can import their own data. I was wondering how I can extract those xml parsers into a bundle or a library so I can use them both in my iPhone app and in a command line app where I just populate a sqlite3 database.
Thanks in advance!
Create a static library project, then use the interproject dependency feature of Xcode to build them in the correct order and link the app with the static library. You'll need to have a common build directory set for all the projects for this to work correctly (at least you did around Xcode 3.0, didn't check if this is still a problem with 3.1).
You can set the build directory from the target or project's build settings (in the Get Info pane). To create an interpoject dependency:
Drag the library project into the application project's Files & Groups pane.
Set up target dependency in the application target's Get Info pane. Make it dependent on the library's target.
Drag the library product in the application target's Link With Libraries step. You can find the library product by expanding the library project within the app project's Files & Groups (click the arrow).
Sounds more complicated than it is. It isn't much.
(Small extras: yes, you need a common build folder as indicated in the Xcode Project Management Guide, and the Xcode Build System Guide can help you "get" Xcode's build system, which -- at the cost of starting a religion war -- I think is one of the most flexible and simple build systems out there.)