Http://www.cocoachina.com/bbs/read.php?tid-282490.html
Xcode6.1 standard framework Static library authoring method. Engineering to the framework, static library plus xib and pictures. Perfect solution. Stayed in Cocoachina for a long time. No big contribution. I have organized this, I hope to help you. Absolutely original. Oh.
1, create a project, or in the original project. Not listed.
2. Add a static library to the original project
2.1, select the bundle for OS X. Because there are no bundles in iOS in Xcode6.1.
2.2, modify the bundle's properties, and let him use it on iOS. The second is to change bundles into the framework
Select the bundle you want to modify
2.3. Target: and choose Build Settings---architectures, Base SDK to latest iOS (iOS 8.1)
2.4, Target: Under Deployment,
Change "Mac OS X Deployment Target" to "Compiler Default ",
Change" targeted Device Family "to" iphone/ipad "and change it according to your needs. If you only want to use the iphone, then choose the iphone on the line
will "ios Deployment Target" and change to "iOS 7.0": That is, this static library supports more than 7.0 versions.
2.5, Target: Under linking,
Change "Dead Code stripping" to "NO",
will "link With standard Libraries "NO",
Change "Mac-o Type" to "relocatable Object File":
2.6, target:packaging,
Change "Wrapper extention" to "framework":
2.6, Target: Returns the info tag.
Bundle OS Type Code changed to "Fmwk" (Framework)
2.7, Target: Return build Phases tags. Add copy Headers, which will be used in the rear.
3, return to the directory, you can see the set of Framewor files. The red rep does not yet have this static library, which you need to generate. I'll talk about it later.
3.1, how to manage the static library:
Click to open the menu and see all the manageable works, static libraries.
3.2:linechart (app icon style) is an app project file, check this run (command+r or command+b) means to have the project exported or tested to run a published application (that is, the online file). The corresponding function will not be introduced.
3.3:pzglinechart (bundle icon style) is a static library. Check this run (running command+b only, not running command+r) means exporting a static library, which is your own encapsulation code, for sharing to others. If you select iOS device run (command+r), the static library version will be exported and the static library version of the emulator will be exported if any of the other versions of iOS simulator (command+r) are selected to run. As for why this, is because the real machine iOS and Mac system in the virtual iOS directory structure is not the same, if the wrong, the compiler will error, "Cannot find the specified file." ”
3.4: Check: Edit Scheme ... : Manage all project files, static libraries, tests, releases, etc. in the program.
Here, we have just joined the Framewor import so that the program directly establishes the relationship.
Become like this:
3.5: Check: Manage Scheme ... :, add delete here, will change
。 Mainly for the convenience of developers to test the use.
If you want to test other projects, static libraries, and so on in the Test menu, add them here, such as the one below. After the Show check box is selected, the menu will come up with both options. Remove the checkmark and hide it.
4, add files to the static library, xib, image ....
Directly describes its properties:
1: Don't know. No use. and other experts to add
2: Program Files Place: (*.M, *.MM, etc.), need to compress the protection of the Code, as long as the files placed here, will be compressed by the static library. A party that uses a static library cannot see the source code.
3: Where the library files are placed, such as the other static libraries, dynamic libraries to compress here.
4: Where the resource files are placed, pictures, audio and video, Xib, Images.xcassets, or even Main.storyboard (storyboard); As long as it is put here, it will be compressed and the user cannot compile or see the source generation.
5: External interface. The main is here, unfold, you will see the first line (public), do not introduce it, look at English should be able to guess, not to mention the word is a common word in the program, Common! , as long as the files placed here will be exposed to the user, it is recommended to put all the *.h files here.
Drag and drop the file you want to manage now, one by one. is not an introduction.
6, first Test, the program part is running normally. I added a new Myviewcontroller (with. Xib) and wrote a simple print in myviewcontroller.m.
And that's what I'm dragging and finishing:
7: Generate a static library: Everyone saw, is red, meaning that Xcode can not find the file, don't panic, we all give him to run one side.
7.1, select the following, respectively Command+b.
Black,, .
Select Pzglinechart.framewor file, right mouse button, Show in Finder.
See, success, it's so simple. Now the real machine version is generated, if you need a static library used by the simulator, check the simulation and then command+b it separately.
Simulator version:
Simulator version is selected: Debug-iphonesimuator folder. If you do not have a Debug-iphonesimuator folder, then you choose
and then command+b.
8, about static library reference files
If you want your project to be exported to a static library in the future, follow the static library reference principle when you write it, using this approach.
Note: This reference must be made in a static library under your products to be black before it can be compiled.
9, create a new project and add the static library you made. Docking well, and then directly command+r. Did it succeed. It's really that simple.
An error about the file cannot be found: look directly below. I have introduced,
Run a successful project, everything is OK.
10, about the third-party library cannot find the file prompt error. Just add it, don't go on a detour.
First, you need to determine the cause of this error: roughly two kinds,
A: You do the project missing documents, Baidu, join on the solution;
Second: You introduced a third-party framework where file errors cannot be found: There are two kinds of results:
Two or one: developers of third-party frameworks are not well-prepared for their own frameworks. In particular, when creating a framework, it is not set to its own properties. Causes the user to use the time to appear cannot find the file error, finally forced the user not to change his project configuration.
Two or two: when you introduce a third-party framework, you rarely cite files.
OK, after you have finished the analysis, we do this static library does not set its own compatibility properties, so it is the error. Running on the ipad Retina Simulator is normal, and replacing it with other analog devices is an error. So it can be solved by changing its properties.
Target: Build Active Architecture, build Settings-I, architectures, change to No;
"I can't get a picture." Downstairs on the 8 floor to find it
Analysis Reason:
When we generated the static library, we chose the ipad Retina. In other words, this static library must also be an ipad Retina when referenced. Otherwise, the Xcode compiler will not find the file.
You can experiment with the ipad retina to export the static library, in other projects when used, if the ipad retina run without errors. If you select a different device, you will be prompted not to find the file.
Compatible with all devices Workaround: Change the compatibility property of the static library. Target: Build Active Architecture, build Settings-I, architectures, change to No;
Build Active Architecture only
This property is set to Yes, in order to debug the compiler faster, it only compiles the current version of architecture, so will be error compiled file, error ("_objc_class_$_xxxxxx", referenced from:)
When set to No, all versions are compiled, which solves the problem of compilation errors.
This is the device corresponding to the architecture:
Armv6:iphone 2g/3g,ipod 1g/2g
Armv7:iphone 3gs/4/4s,ipod 3g/4g,ipad 1g/2g/3g
Armv7s:iphone5, IPOD5
Arm64:iphone5s
The compiled version is backwards compatible, such as you set this value to Yes, compiled with iphone4 is the ARMV7 version, Iphone5 can also run, but the ARMV6 device cannot run.
real-machine and emulator-version library merge workaround:Under the Framework folder, you will see a whiteboard file with the same name as the framework static library, except for the suffix name. This file was invisible when it was introduced to other projects. Can be seen only in the show in Finder.
Open terminal, enter command: Chinese to your real directory.
Lipo-create "... Real machine/directory/That whiteboard file "" .../simulator/catalogue/That Whiteboard file "-output" ... save/directory/File "
Merge the new files and overwrite the files in the original framework. This framework will support all the devices and the real machine, the simulator all versions.
In fact, this method is to use the *.a file merge method. As effective as the framework. Whiteboard files in the framework are like *.A files.
9, reference to Xib. The same way you create the framework on top of the same root, just set it differently. I added a name for: resource.bundle static resource file.
This way:
Target: and choose Build Settings---architectures----to latest iOS (iOS 8.1)
Target: Under Deployment,
Target: Change "Mac OS X Deployment Target" to "Compiler Default",
Target: Change "targeted Device Family" to "Iphone/ipad",
Target: Change "ios Deployment Target" to "iOS 7.0":
9.1. Write in the myviewcontroller.m file. Don't forget to write the interface in the *.h.
9.2. Then drag and drop the new resource file.
Select the project file and drag it back (the project to the Static library).
For ease of viewing, I painted the myviewcontroller.xib background blue and added a red button. Direct: Command+r. Everything works fine.
9.3, then the two files are copied out.
Put it in another project and run it. is not very simple.
10, add a picture. How to add or not explain. Add a picture that is not managed by the manager first.
Engineering Command+r. Everything is fine.
10.1, other projects refer to the static library, and then run. Normal. Hey, is not more than a picture file.
10.2, improve the difficulty, we add pictures in Images.xcassets Picture Manager. I added a matrix picture and set the Matrix property.
Add a button to the xib. Full device matching button. I didn't write a single line of code, just xib the button. Then set the next background. The system automatically recognizes the picture. About this everybody can degree niang under.
Regardless of 3,721, pull the images.xcassets directly to the repository.
Engineering Run,OK. No problem.
Introduce a static library. Ok. No problem. There was no discovery. One more unknown file: Assets.car. This is images.xcassets management, inside all the pictures are encapsulated, that is, the images.xcassets management of the image is also protected by encryption. Go crazy. Shout it out. Oh, "yards of farmers" a group. Change your mind quickly, or you'll soon be out of Apple.
Xcode6.1 standard framework Static library authoring method. Engineering to the framework, static library plus xib and pictures. Perfect solution.