https://agilewarrior.wordpress.com/2016/04/04/how-to-add-xcode-subproject/
Create a blank iOS project that you’d like to use a static library in.
Then create a new static library project of type Cocoa Touch Static Library
Define some method in your static library class that you would like to call from your other project.
If you build this now you will see a libStaticLibrary.a file
And if you right click a view in finder you’ll see
There are two parts. The header file is what you other project will need to compile. The lib*.a file contains the executable.
Note however though that this library is currently only build for the Debug-simulator. That means it won’t work on a real device.
x86_64 (i386)
architecture is required for running the 64bit simulator.arm64
architecture is required for running the 64bit device (iPhone 5s, iPhone 6, iPhone 6 Plus, iPad Air, iPad mini with Retina display).
To make it universal we add a Aggregator target to our static library project.
And then add the following build script by selecting Project -> UniversalLib target, ‘+’ sign
And then copy/paste the following script into there.
# define output folder environment variable UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal # Step 1. Build Device and Simulator versions xcodebuild -target ${PROJECT_NAME} ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" xcodebuild -target ${PROJECT_NAME} -configuration ${CONFIGURATION} -sdk iphonesimulator -arch x86_64 -arch i386 -arch armv7 -arch armv7s -arch arm64 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" # make sure the output directory exists mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" # Step 2. Create universal binary file using lipo lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a" echo "Universal library can be found here:" echo ${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a # Last touch. copy the header files. Just for convenience cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/"
This script builds the project and creates a universal library using a tool called ‘lipo’. Run this UniversalLib target
Then go back to the finder on the libStaticLibrary.a we opened earlier and you should not see a universal folder there containing your universal library.
This is libStaticLibrary.a and StaticLibrary.h are what you need in your other project to use this library.
Go to the project where you want to use the static library, and control drag these into a directory there.
Use your newly imported static library somewhere in your code:
And now try to Run. It should now work.
Then whenever you add a new file, just add it to the project target Build Phases -> Copy Files
That’s one way to import your static library. The other way is to import it as a subproject.
https://agilewarrior.wordpress.com/2016/04/04/how-to-add-xcode-subproject/
Export your public headers (optional)
Close your static library project (else you won’t be able to drag it into your main project).
If you want to import your static library as a subproject, you need to publicly expose your library headers. Do that by going to UniversalLib (the aggregator) -> Build Settings -> Public Headers Folder Path + and enter the name of your library
Then when you include this subproject in your parent project goto Build Settings -> User Header Search Paths and add $(CONFIGURATION_BUILD_DIR) (non-recursive) so it knows where to find them.
Note 1: If you do this, you will need to import your library header with the angle brackets and not the double quotes, like so
Setup other linker flags (optional)
Because objective-c categories don’t be default link in static libraries, turn on -ObjC flag to share your internal categories with external clients.
To use Objective-C library add -ObjC to Other linker flags of parent project under Build Settings.
Add new class to library
When ever you want to add a new class to your library and expose it to the outside world add the header file to the CopyFiles section under Build Phases
Add then run the build aggregator
And then import the header as regular if internal to the library
Or square bracket if external to library
Subproject arrow not expanding and showing up in parent
You won’t be able to add you static library if you have it open in another xcode window. Close it and it will show up correctly.
https://www.raywenderlich.com/41377/creating-a-static-library-in-ios-tutorial
http://www.technetexperts.com/mobile/creating-static-library-in-ios-app-development/
Dec 23, 2016 @ 16:41:07
Feb 23, 2017 @ 21:24:33