iOS 8 custom framework linking issues - ios

I'm having issues linking to my custom iOS framework which make me realize I don't fully understand the concepts behind this process.
Basically I have a framework project created using the new Cocoa Touch Framework template, and a client project that uses the framework. If I add the framework xcodeproj file to the client project everything works fine. But if I have the 2 projects side-by-side in a workspace I can't get the client project to recognize the framework. I've tried adding it as a link binary but it displays in red, and I've tried adding the header #import statement (which produces the error "unable to build module").
I'm unclear what files the framework should produce as output and where it should put them (I can't find any), and what is needed for the client project to recognize them. Does the OS (or simulator) take care of locating them or does the client have to reference a specific location? Why (and how) does it work when the xcodeproj file is included in the client?
Thanks

Related

Developed a framework, Cannot load underlying module for 'x'

First I have did tons of researches on this issue. Non of existing solution similar to my issue.
I developed a framework. It is a pretty heavy framework which include a c++ static library and contains both objective-c and swift codes. I have created a sample app that imports my framework to mimic the behaviour of people can using my framework.
I put the framework under a libs folder of the project. I have make sure the framework is under Embedded Binaries and Linked frameworks and Libraries. I have also make sure that the path to libs folder exists under Framework Search Paths and Library Search Paths and User Header Search Paths.
Now When I run the sample app using my actual device and running on the computer that contain my framework project file, it works perfectly.
However If I run the sample app using simulator devices, it told me No such module x
Moreover If I run the sample app using my actual device and running another computer that I didn't use to develop my framework project, it shows error Cannot load underlying module for x.
Has anyone had this problem before? Any hint would be appreciated.
(I have also tried clean, clean build folder, clean Derived Data, restart Xcode, restart computer etc.)
Solved problem by setting Defines Module to No

Xcode Create a swift framework that itself uses cocoapods

I'm still relatively a beginner. I'm trying to create a uber type app that uses firebase database (installed via cocoa pods). I'm creating an app for drivers and another for riders. I'm also trying to start out right by structuring my app as best i can to begin with.
In the riders app, I created a database handler singleton to control access to the database including functionality to add the rider to the database. A common firebase database is shared by both apps. Rather than have both apps have separate database handlers (and various other independent handlers), I've created an independent swift framework to hold the handlers.
I've added my swift framework to the top level of my workspace in both the rider app workspace and in the driver app workspace (by dragging in the framework xcodeproj file) and gone through all the processes I've read about to build the framework to a generic device and copy the framework to the actual app embedded binaries etc. Independently both app workspaces are working properly .... however ... i have 2 problems at this stage
if i try to open both workspaces at the same time (ie work on the rider app at the same time as working on the driver app), Xcode gives me a workspace integrity error basically giving error "couldn't load xcode project (ie the framework project) because it is already opened from another project". the app still runs ok but the error (red error) remains. how can I fix this?.
I want to use FirebaseDatabase within the database handler framework itself but even though I have FirebaseDatabase installed in the main app, the framework can't see it ie import FirebaseDatabase line is showing "no such module". I also tried installing FirebaseDatabase via cocoa pods separately in the framework project and am still getting the same "no such module" error. How can i get the framework code to see the required cocoa pod frameworks
Having a shared framework project outside of two app projects, but included in their workspaces can cause problems. Editing the framework in one workspace may break the app in the other workspace if the change is a major one.
I think you have two options. One is that you keep the framework app in a central repository and check it out into the app projects. This lets each app project use the version of the framework they are comfortable with and if one changes, the other doesn't see those changes until you tell it to update.
Another option is to switch to a single workspace with both apps and the framework in it. Effectively saying that you will always be working on both at the same time and they will always be in sync.
I can't say what the issue is with not finding the framework as I don't use CocoaPods, but I'd be checking all the framework search paths in each project settings to see if they are searching the right directories for the compiled frameworks. You should not be copying any dependency frameworks in the framework target, but all of them will need to be copied in the app targets.

IOS: One 'Cocoa Touch Framework' Library for both Simulator and Real-Device?

I am working with XCODE 6 and SWIFT 1.2 in my iphone application at the moment and loooking a way to share the common codes between projects.
Therefore thought of creating a 'Cocoa Touch Framework' as explains in following tutorials that contains the codes I want to re-use among projects.
1). How to reuse Swift code in other projects?
2). http://locomoviles.com/ios-tutorials/create-ios-cocoa-touch-framework-using-xcode/
3). https://www.youtube.com/watch?v=86cPaa3FrRg
All ok and I can use the shared codes that contains in the Library project successfully.
So my problem is, this is really annoying I have to integrate framwork that contains in 'Debug-iphonesimulator' folder when testing with simulator and again the library that contains in 'Debug-iphoneos' when testing with a real device...
I see Three folders as follows (Built libraries)
Just generated the release library (the content in 'Release-iphoneos' folder) thinking that this may work in both deice and simulator. But again this works only with real-devices, and not with simulator.
Question 1). Can't I generate one library that can build and use in both 'simulator' and on a 'real device'?
Question 2). Is there any other way I can link (reference) to Framework Project directly rather than integrating a build library? So Project reference to external Framwork and use resources in there (No library integration... Referencing to project like eclipse android libraries and projects)

How to build iOS framework with XCode 6

I know of familiar tutorials on this, but introduction of framework XCode 6 template has changed the game.
I already watched WWDC 2014 video about building modern frameworks but it talks more about building extensions, framework & app all inside single project. It does not specify if the framework I make with it is truly reusable across any project.
I am building framework the XCode 6 way (File->New Project->Framework and Library->Cocoa Touch Framework), but when I import it inside my test app project (separate from framework project) - I keep getting various errors.
Example: Include of non-modular header inside framework, and so on.
I know this is not what it says, and there are quite some missing steps in whatever I am doing. The older tricks may have worked for everyone, but I simply don't find which way to follow after XCode 6.
For example, there is some folder structure that a framework needs, but XCode 6 doesn't comply to it while building it. Is it right? If not, how can I change the way the XCode builds framework folder hierarchy?
Do I go back to old school or am I screwing some tiny thing in XCode 6 that I am unable to create a reusable framework?
I am not sure if you are trying to build a framework with Objective-C or Swift as your question doesn't state it. I've encountered errors you are mentioning with Swift so I'll give you my method to build Swift frameworks.
I found the process for Objective-C to be very straightforward and well documented, so I'll skip this.
As for Swift, there are a few things to consider. First, Swift static libraries are not supported, so you must exclusively use a framework (aka dynamic library) when linking an app to a library.
Here are the steps:
Create the Framework using New > Project under IOS > Framework & Library, select Cocoa Touch Framework
To avoid the "ld: warning: directory not found for option..." goto Library Search Paths in Build Settings for your target and delete the paths.
You can't mix Objective-C with Swift so don't even consider adding the Swift-Header bridge file in your code.
There are some cases in swift where you need to import code from unexposed Frameworks. I've successfully used the module-map inside the framework to deal with these case.
I also select CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES in the Build Settings to solve 'include of non-modular header inside framework module'. That seems to work
I make sure that the header file that gets generated is marked as Public (not Project). Click on the file and you'll see the selection in the inspector under 'Target Membership'
You may run into some bizarre error messages when building. Xcode has a tendency to report linker errors when your code can't compile correctly resulting in missing files the linker needs to output its binaries. Sometimes XCode won't show the errors in the files you are compiling and you need to go manually on the build output and go back to the files. Some other time, you'll get a problem where you need to delete the cache. Those issues I call XCode blues and deal with it constantly. I found this type of problems happens more often when building libraries. The rest should work as expected.

Reference code in a separate project in XCode 4.2

I'm working on an iOS app where I use third party libraries. I want to migrate my project to use ARC, but the third party libraries are still using the old memory management. So I want to separate third party code and put it in a separate project without ARC, and then somehow link that project into my iOS-app project, so that they will be built together using the same configuration.
Is this possible to do in a very simple way, or am i better of just turning off ARC for the individual files? (seems very tedious..)
Can I use a workspace? Where one project is my iOS app and the other just contains third party code?
I've played around a bit and googled a lot, but there just doesn't seem to be any simple soultion, or am I wrong?
So I figured it out myself, with a lot of help from different blogs. Something this basic should be more trivial and well documented... But here we go, this is what I did to get a library for AsiHttpRequest:
Create a new iOS project. Select the 'Cocoa Touch Static Library' template. Call it whatever you like. You don't want to tick 'Use automatic reference counting', since AsiHttpRequest does not support it.
Select a location for your library project (will matter later on).
Delete the default .h- and .m-file created by Xcode.
Drag and drop the AsiHttpRequest files into the project
You can add the frameworks that AsiHttpRequest is dependent of, but you will have to add them to your main project anyway, so it is not necessary.
Try to build the project, it should do so without errors.
Open your main project
From finder, drag your library .proj-file into your main project (in Xcode, so that it 'lands' onto the main project file)
The library project should now appear under your main project (still in XCode). It should be expandable and you should be able to see the library project files as well. If it doesn't, try closing all open projects and reopen the main project.
Select the main project, and select target. Under Build Phases - Link Binary With Libraries, click the +-sign.
In the list of frameworks you should see your library project (called something like libname.a). Select that file
The newly added file might appear red in the list of frameworks, don't worry, it works anyway. Guess it's a bug.
Still under target, go to Build Settings
Under Header Search Paths add the relative search path to where the library .h-files are. This is relative to your main projects .proj-file. (For example ../some folder/libproject/)
Hopefully your main project will build without errors and the library project will be built at the same time, using the same configuration as the main project.
I have no idea if this is a good approach or if there is some easier way to do it. However, I like this, since I can use the library project in several projects. And if I want to update the library project, I only have to do it in one place, and the other projects will be updated as well, since they all reference the same project.
Edit1:
I had some problems with library projects using objective c categories. I received unrecognized selector sent to instance errors in runtime when trying to call those methods. This problem was solved by following the answer given here.
Go to build settings of the target in the main project and add -ObjC to the entry called Other Linker Flags
Edit2:
I found this template for creating Universal frameworks. I haven't tried it, but I guess something like this would work as well.

Resources