I can include a framework like so in a TemplateInfo.plist file:
<key>Frameworks</key>
<array>
<string>QuartzCore</string>
<string>OpenGLES</string>
<string>OpenAL</string>
<string>AudioToolbox</string>
<string>AVFoundation</string>
<string>UIKit</string>
<string>Foundation</string>
<string>CoreGraphics</string>
</array>
But I cannot find how to do something similar with static libraries. This would greatly improve my template. Is there such functionality?
Link Static Library to your App Right-click on your libStaticLibrary. a choose Show in Finder, copy files and put them to a created new folder which the name “lib” in the root folder of your project. Create new single view application or open your project where you want to use your library.
Open XCode and start a new project. Under iOS, select Library and “Cocoa Touch Static Library” say it as "staticlibrary". This will create a nice new project for us that builds a . a file.
Create Static Library Project Open Xcode and select Cocoa Touch Static Library . Give it a name and select Swift as the development language. In our case, we will call it Networking and assume that it will contain the code to communicate with a back end. Press Cmd+N and select Swift file .
I found a solution.
In templateInfo.plist add key Targets --> SharedSettings
<key>OTHER_LDFLAGS</key>
<string>ObjC -all_load -weak_library /usr/lib/libz.dylib ..</string>
It adds your dylib to debug and run settings.. doesn't work with autocomplete as xcode can do with frameworks, but still lot better than doing it manually
EDIT: expalin
<key>Targets</key>
<array>
<dict>
<key>Dependencies</key>
<array><integer>0</integer></array>
<key>Frameworks</key>
<array>
<string>CoreAudio</string>
</array>
<key>SharedSettings</key>
<dict>
<key>OTHER_LDFLAGS</key>
<string>-ObjC -all_load -weak_library /usr/lib/libz.dylib -weak_library /usr/lib/libstdc++.dylib </string>
</dict>
</dict>
The best way I found for doing this is to create an alias to the /usr/lib directory inside your templates folder. From there, you can access all the libs which are in /usr/lib, even the ones which are aliases themselves.
First, I create templates by editing the .plists in XCode, not by editing the xml representations themselves. So, that's how I will be explaining the steps I took to include static libraries into my template.
1) I have a project template: iPhoneOS.platform / Developer / Library / Xcode / Templates / Project Templates / Application / C4 Application.xctemplate
(In Xcode 4.3 the Project Templates / Application can be found directly in the Xcode.app by right-clicking the bundle and choosing Show Package Contents)
The guts of this folder look like this:
2) As you can see in the image above, I created an alias for the lib folder (/usr/lib
) that contains static libraries and moved the alias into my .xctemplate folder.
3) In my TemplateInfo.plist file I specify 2 things: a Dictionary and a Node. I put them inside the Definitions and Nodes of the TemplateInfo.plist
First, in the Definitions node I specify a dictionary called: Libs/libalias.dylib
Inside this lib I have 2 strings Group : Libs Path : lib/libalias.dylib
The node looks like this:
It is important that the syntax be exactly like this, and most importantly that the name of the Dictionary itself specifies the library you want to import. In this case I am importing the libalias.dylib library.
It is also important that the Path be lib/libalias.dylib because this will point to the alias which points to your /usr/lib folder.
Second, in the Nodes array I specify an item as a string which is called Libs/libalias.dylib (note: the exact same name as the Dictionary I specified in Definitions)
This is what the Node Item should look like.
4) Once you have these things set up, you can create a new project with your lib already included.
NOTE: because I called my Dictionary Libs/... and specified it's Group as Libs the library I am importing appears in a subfolder called Libs in my Project Navigator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With