iPhone SDK: How to add a compiled static library to my project?(AQGridView) - iphone

I plan to use AQGridView which I found on github, it says:
"This project compiles to a static library which you can include, or you can just reference the source files directly. Note that there are some resources to copy into your project for the tableview-style selection backgrounds."
But I have no idea what does this means, can anyone one tell me clearly the steps how can I add this to my project?
Thanks

After compiling the project, you'll get a dylib-file (you may already have it?).
Now, drag the dylib-file to your app-Xcode-project.
Go to your target settings and add the includes-folder to your Header Search Paths so that you can use it's public classes.
Now make sure it's in your target's 'Link with library'-list.
Compile!

Related

Balanced Payment integration for iOS

I am trying to do the payment using https://www.balancedpayments.com/ . They have their iPhone library for this https://github.com/balanced/balanced-ios . The problem is that there is not enough documentation on how the Balanced.framework has to be added in the XCode 4.5 project?
Download the Balanced framework.
Add Balanced.framework to your project and to Build Phases -> Link Binary With Libraries.
Add CoreTelephony.framework to Build Phases -> Link Binary With Libraries.
Usage:
#import <Balanced/Balanced.h>
Balanced *balanced = [[Balanced alloc] initWithMarketplaceURI:#"/v1/marketplaces/TEST-MP2autgNHAZxRWZs76RriOze"];
BPCard *card = [[BPCard alloc] initWithNumber:#"4242424242424242" expirationMonth:8 expirationYear:2025 securityCode:#"123"];
If you need more help, look at the example project they have attached...
You Just Need to add those Balanced- Classes as a static library, It will work out.
Add a Static Library to your Project.
Now add those balanced classes to your static Library.
Goto YourProject->Target->BuildPhases->LinkWithBinaryLibraries
Here add the StaticLibrary.
Hope this will help you.
Follow this issue on Github. The lack of linking Balanced.framework is related to Xcode templates. The fix is documented in the project's "Contributing" section. You need to build it.
The balanced-ios project has changed quite a bit since this question was asked. It now creates a static library instead of a framework. This change was made for the reasons described in balanced-ios Project Architecture.
To integrate balanced-ios into iOS projects, do the following:
Download the latest pre-built release zip from https://github.com/balanced/balanced-ios/releases
Copy balanced.a to your project
Add balanced.a to Build Phases -> Link Binary With Libraries
Add CoreTelephony.framework to Build Phases -> Link Binary With Libraries
Copy includes/balanced to your project's include folder (or create an include folder and copy includes/balanced to it) includes is automatically included in header search paths. Drag includes to your project so you can see the files from there. If you copy the include files to a location other than includes you'll probably need to add the path to User Header Search Paths in your project settings
Code usage examples can be found in the README at https://github.com/balanced/balanced-ios

why do I get this error building a static library for my iPhone project using XCode 4?

I have an existing iPhone application, and I just wanted to make a static library out of the code, so that I can use it by a separate test application (within the workspace). The application compiles fine, but when I try to compile the library version (which has the same code files) I get the following error:
Lexical or Preprocessor Issue - "MyClass.h" file not found
However, the application still runs, even through there is this error. In fact when I compile the application (which uses the static library) it initially says no errors, and then after a second or two the above mention error then appears.
I'm basically doing:
Create a new target in the project using the Coco Touch Static Library
Add the .m files in the targets "Compile Sources"
Adding the .h files in the targets "Copy Headers"
Adding the same set of libraries in the "Link binaries with libraries"
Go into the Profile and modified the Target to be RELEASE
Any suggestions? Am I missing a step here?
I'll have a stab at this :-) I think it might be that MyClass.h has been set to private. Thus it is not added to header directory when you create the static library. You should check to see if this is so by checking the output header directory. If the header file is missing, then it's pretty sure thats whats going on.
Secondly, why use a seperate app for testing and therefore require building a static library at all? I have several static libraries and apps which I unit test with GHUnit. I do it by simply adding a new app target and configuring it to run the GHUnit iOS app. I can then add the classes I want to test and any testing frameworks such as OCMock without having to create separate projects. Basically it sounds like your testing methodolody is perhaps more complex than necessary. :-)
So, the issue turned out to be I had "-ObjC" set in the "Other Link Flags" option, which I'd put there as at one stage trying to get things working I read this was required - Dereks advice to review the compilation log worked well here

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.

two projects in xcode4 workspaces (#import failure)

I'm really struggling to get this to work in xcode 4.
I have one project that I will reuse in many applications (networking) so I create a workspace and add my two projects. So far so good....
This is where it fails..
#import "JSONRequest.h"
For no apparent reason. It auto completes the file name of the header file. I thought this had something to do with the "scheme" (also new in xcode 4) so I've tried to add my networking target in the build phase. Changing order of them... set "Shared" under Manage schemes.. I've tried so many different combinations of the settings without any success.. And the error message is get is:
JSONRequest.h: No such file or directory
If you have a clue, please let me know.
You can add the header or source folder of your project you're referencing to your Header Search Paths.
Click on the target that's importing JSONRequest.h.
Click on Build Settings.
Enter "Header Search Paths" into the search box.
Double click on the value cell.
Click the + sign.
Set the path to the project you're referring. Let's say it's called JSONlib. The path is relative to the root of the referring project (the project that's using JSONlib). For example: ../JSONlib/src/headers/ or wherever it is that the .h file lives.
Click done.
Clean and then build.
You'll find more info about this problem in the apple developer forums. Best of luck.
What are you really trying to do?
If you have an entire Xcode project you intend to share between different products that usually suggests your project builds one or more targets (such as a framework, etc.). Therefore, your "shared" project should be able to build the framework on its own, irrespective of the workspace it's contained in, right?
Let's assume it's a framework. In most cases, Xcode can figure out the dependency by simply adding the framework product to the Link build phase of the (assumed) app using the framework. Done. Xcode should know to build the framework project's target first, since it's linked against when building the app project's target.
So your problem is likely just a matter of knowing where Xcode is looking to find files. Since projects within workspaces share that workspace's build folder, they can all "see" each other. But in the case of a framework, A simple import by file name won't cut it. You'd need:
#import <MyNetworkingFramework/MyNetworkingFramework.h>
Since you're including a specific header (JSONRequest.h) (which must be one of the public headers in the framework target's copy headers build phase), you'd need:
#import <MyNetworkingFramework/JSONRequest.h>
If your "shared" project is not a framework, you'll need to amend your question to include a more thorough description of your two projects and their targets.
This worked for me,
In build settings --> Header Search Path --> Add below entry
$(SRCROOT) and mark it as recursive. If above not worked you can also try following way, <path-of-other-project> and mark it as recursive. Hope this helps to you ! (You may require to clean or restart the workspace)

How to use a loadable bundle from a static library?

I've created a static library "MyLib.a" with its loadable bundle "MyLibBundle.bundle" which contains all needed resources such as my xcdatamodel and xibs.
Now, I want to use that library in another project.
So, I included the "MyLib.xcodeproject" in the new one, linked the library and specified the headers search path.
But, after all, the application can't find my core data file (SIGABRT).
Does anybody have a solution?
We had the same problem.
Here's the best way we have found so far:
drag you lib.xcodeproject in your project
build the lib from your project using the correct scheme
expand the tree structure until you see the product produced by the build
right-click, select 'show in finder' it should end up being in ../DerivedData/Projec-HASH/Build/Products/etc...
drag the .bundle in your project source
set it to relative to build products (right pane)
Now, in your main scheme, add the bundle as a target to build before your app itself.
Also, uncheck parallelize checkbox and make sure the bundle is above the app. This ensure your bundle gets built first, then your app will build.
Hope this helps!