Dynamically link binaries with library in xcode - ios

To link binaries to you framework you can from build phase add your needed libraries to your project .. but what if I need to make some thing specific for example I need to customise my framework by adding or deleting binaries.. foe example I want lite version and full version so I need always to delete and add these binaries from "Link binary.." tab
Is there any dynamic way like to make different configuration files or some thing?

You'd need to create 2 Xcode targets, one for lite and one for pro, which compile the same source files and link to mostly the same frameworks etc.
You can also add compiler constants to the Build Settings of these targets, which will allow the common source files to behave differently between these target "products".

Related

Add Files and Select Multiple Targets in Xcode

I have over 100 projects in my XCode and when I add a new file or class I have to select each target one by one to add it to it. Is there a way to select multiple targets instead?
The usual way is to have targets that don't duplicate each others files. E.g. some targets are libraries that are used by some others, and eventually there's an app or a unit test target that uses them. In this case there's no need to have the same file in multiple targets.
So consider refactoring the common files to a common library target that you can reference from the other targets. In this case when you add a file, you can add it to just that library, and it will be automatically resolved (linked) in the other targets.
Note also that in this case the file you add is only compiled once, and the compilation result is reused in various dependant targets, as opposed to compiling a separate version of that file for each target.
If that's not an option for you, an alternative is to generate the Xcode project file using some tool like CMake, GN, or a custom script that can write xcodeproj files (there are libraries to do that in various languages).

How to re-export a framework and use it in another project in iOS? (Should I?)

I have two projects I'm working on in XCode. Project 2 depends on Project 1, and I want it to be able to use the same frameworks I have embedded in Project 1 (they're Carthage dependencies). I discovered the "Re-exported Framework Names" section in Build Settings, but I'm not at all clear on how I might use it.
What should I put in that field? Just the name? (PromiseKit). Or the filename (PromiseKit.framework)? Or the full path?
How do I then reference this framework in Project 2? Right now I'm getting a build error: framework not found PromiseKit for architecture arm64 and I can't see any obvious way to add that framework link.
And a broader question: do I need to do this? I'm a relative newbie and working on the assumption that setting up separate Carthage dependencies for both projects means that there will be two separate compiled frameworks in my final binary, which would be a waste. But is XCode cleverer than I think and taking this into account?
If the two projects are related, put them in the same Xcode workspace and then you can share the frameworks between the two.
If the projects are independent, put the frameworks into a separate folder, add them separately to both projects and when adding them to the projects, don't choose Copy files if needed.

Why are some linked frameworks look like a piece of Lego, while others like a toolbox?

I just noticed that some of the pods that I added appear as a Lego bricks:
And some pods appear as toolboxes:
in the linked libraries and frameworks section. As a whole, all my pods look like this:
Why is that?
Since the name of the section is "Linked Frameworks and Libraries", I assume that one of the icons represents a framework and the other represents a library? But which is which? And how does Xcode know that it is a framework or a library? I checked the podspecs of the pods but I didn't find anything about frameworks/libraries.
Toolbox is a standard icon for CocoaTouchFramework and it's usually mean that it uses Foundation framework.
White Cube (lego bricks) means bundle. That can link whatever you need, it can be a pack of Localized.strings (ex: ZendeskSDK) or other assets.
Please note that there is a difference between how it's displayed inside Linked Frameworks and Libraries or Embedded Binaries than it is inside Finder.
And framework to work with both Simulator and Device must be built with different architectures (x86_64) vs (armv7,arm64). And it's handled by Xcode what to take from .framework, since you don't need to link it manually against different architecture. So in Xcode point of view, you always have in this section right .framework file ready for your architecture, so it can be displayed as toolbox. In your case library LTHPasscodeViewController does not contain autobuilding scheme (like SwiftyJSON for example). No xcodeproject besides demo, classes are not linked to .xcodeproj, so it's not created from CocoaTouchFramework.
When you select new Project from Xcode and choose Cocoa Touch Framework it create project for you. When you don't have a project it's just bundle (doesn't matter that has .framework extension).

Script to add list of framework into xcode project? [duplicate]

I am looking for a way to add libraries to an Xcode project, using the command line.
I have been successful in adding files to groups with the XCS tool, but it does not support libraries.
I would, for example, like to be able to add CoreVideo.framework to a specific project with a command on the Terminal.
This project can handle frameworks:
https://github.com/kronenthaler/mod-pbxproj
Just add it as a normal file, it will figure out the correct type and how to set everything up (i.e., add it to the link library phase – before using it, you still need to import the header(s), of course).
// libFilePath: Path to the framework
frameworkGroup = project.get_or_create_group('Frameworks')
project.add_file(libFilePath,
parent=frameworkGroup,
tree='SDKROOT',
weak=True)
You can decide whether you want to weak-link frameworks (see code example) or not (just leave out the last parameter, it defaults to False). You can find the code to open/save Xcode projects in the repository.
Another way to do it is adding linker flags directly, e.g., -framework CoreVideo.framework. If the framework paths are set up correctly, you don't have to provide absolute paths. The disadvantage of this approach is that the linked frameworks aren't obvious if you open the Xcode project, as they are not part of the link library section, nor does the framework show up in any Xcode group in the Project Navigator.
You can try generating your .xcodeproj using tools like XcodeGen. It allows you to include different types of dependencies.

Compile different files for device/simulator in XCode

I'm including a 3rd party library (sources) with my static library. It it intended for device only (since it includes some ARM assembly routines) and I do not wish to build it for the simulator (I just want my app to compile there so I can test the GUI).
Creating another target for simulator only is not an option since my projects reference my library as a dependency and it would be a nightmare to maintain.
Adding #if (TARGET_OS_IPHONE) for those files is not an option as well since these are not my original sources and I would like to update them easily for updates (there are more than 200 files there and I do not with to modify all of them)
I'm looking for a way (similar to #if (TARGET_OS_IPHONE) in source files) which will work from the IDE itself (so I can exclude a file from the actual build process based on my target architecture). The only thing I found is an option to exclude/include a file from a target - but not for a specific architecture.
Is there a way to set architecture conditions per specific files?
Your best bet would be to separate the third party library into a new target that builds it as a static framework. Set it as a dependency for your project, and then set the static framework to be conditionally linked as described by Apple here: http://developer.apple.com/library/ios/documentation/Xcode/Conceptual/ios_development_workflow/115-Configuring_Applications/configuring_applications.html#//apple_ref/doc/uid/TP40007959-CH19-SW7
You can add a new target by selecting the Project in the project navigator and then hitting the Add Target button at the bottom of the Editor pane. You can setup a cocoa touch static library and then assign the relevant .m or .c files to belong only to that target. Then select your app's target and add the static framework in the "Target Dependencies" section of the Build Phases tab.
You can conditionally include/exclude files in Xcode using EXCLUDED_SOURCE_FILE_NAMES based on sdk. For example:
EXCLUDED_SOURCE_FILE_NAMES[sdk=*simulator*] = something.cpp something_else.cpp
See Conditional Compilation article for more details

Resources