Current location - Health Preservation Learning Network - Slimming men and women - Why is the ios framework not the code you can see when debugging in binary?
Why is the ios framework not the code you can see when debugging in binary?
I think this packaging framework is still an important function, which can be used to do the following things: (1) packaging functional modules, such as packaging mature functional modules into a package, and then making it convenient for yourself or other colleagues to use in the future. (2) Packaging project. Sometimes a company finds two development companies to do two projects, and then nests one of their projects into another. At this time, it is convenient to package nested projects into a framework. Why do we need a framework? It is troublesome to enjoy this library in a developer-friendly way. You need to include not only the library itself, but also all the header files, resources and so on. Apple's solution to this problem is the framework. Basically, this is a folder with a fixed structure, which contains everything needed to reference the library. Unfortunately, iOS prohibits all dynamic libraries. At the same time, Apple also removed the function of creating a static iOS framework from Xcode. Xcode can still support the function of creating frames. To restart this function, we need to make some minor changes to Xcode. App store allows code to be encapsulated in a static frame. Although the form is different, it is still a static library in essence. Classification of Frames Most frames are in the form of dynamic link libraries. Because only Apple can install dynamic libraries on iOS devices, we can't create this type of framework. Static link libraries are the same as dynamic libraries, except that binary codes are linked at compile time, so using static libraries will not have the same problems as dynamic libraries (that is, no one can use dynamic libraries on iOS except Apple). ? Fake? The framework is implemented by cracking Xcode's target bundle (using some scripts). On the surface and in use, it is no different from a static frame. ? Fake? The function of a framework project is almost the same as that of a real framework project (not all). ? Embedded? Frames are wrappers of static frames, so Xcode can get resources (pictures, plist, nib, etc. ) It's in the photo frame. This version includes the creation of static frames and? Fake? The template of the framework, and both? Embedded? Frame. What kind of template do you use? There are two templates in this version, and each template has? Strong? Weak? Two kinds. You can choose the one that suits you best (or both). The biggest difference is that Xcode cannot be created? Really? Frame, unless the static frame file xcspec is installed in Xcode. This is really a pity (this document is for the project, not the framework). In short, you can decide which template to use: if you don't want to modify Xcode, please use it. Fake? If the framework version just wants to enjoy the binary (not the project), both can be used. If you want to share the framework with developers who don't want to modify Xcode, just use it? Fake? If you want to share the framework with developers who have modified Xcode, use? Really? Framework Version If you want to make one framework project a dependency of another project (through a workspace or subproject), please use? Really? Framework (or? Fake? Frame, use-frame? If you want to add other static libraries/frameworks to your framework project and link them to the final result, you don't need to add them to the user project separately, use? Fake? Frame? Fake? Frame? Fake? The frame is cracked? Relocatable target file? (The target file in a repositionable format can save code and data, and is suitable for linking with other target files to create an executable target file or an enjoyable target file). It allows Xcode to compile something like a framework? It's actually a bundle. ? Pseudo frame? Templates divide the whole process into several steps, and use some scripts to generate a real static framework (based on static libraries rather than relocatable object files). Moreover, does the framework project also define it as a wrapper.cfbundle type, an Xcode? Second-class citizens? . So this has nothing to do with ... Really? Static frameworks can also work well, but they are in trouble when there are dependencies. Dependency problem If you don't use dependencies, it's no problem to just create an ordinary project. But if you use project dependencies (such as in workspace), Xcode is a tragedy. When you click. Link binaries to libraries? Below? +? Button? Pseudo frame? Cannot be displayed in the list. You can start from your. Fake? Manually drag into the frame project under the product, but when editing the main project, a warning will appear: Warning: Skipping file'/somewhere/myframework.framework' (unexpected file type' wrapper.cfbundle' in the frame &; Library construction phase) is accompanied by? Fake? Link error in frame. Fortunately, there is a way to solve it. You can stay here. Other linker logo? Is it useful? -Frame Walker? Switch manually tells the linker to use your frame link: -framework MyFramework warning still exists, but at least it can be linked correctly. Add Other Libraries/Frames If you add other static (non-dynamic) libraries/frames to your? Fake? In the framework project, they will? Link? To the final binary frame file. Are you online? Really? In framework projects, they are pure references, not links. You can avoid this by including only the header files in the project instead of the static library/framework itself (for compilation). ? Really? Frame? Really? Does the framework conform to all aspects? Really? Standard. This is a truly static framework, just as it was created using the features that Apple removed from Xcode. In order to create a real static frame project, an xcspec file must be installed in Xcode. If you publish a book? Really? Framework project (not compilation), people who want to compile this framework must also install xcspec file (using the installation script released this time) so that Xcode can understand the target type. Note: If you publish a fully compiled framework instead of a framework project, the end user does not need to install anything. I have submitted a report to Apple, hoping that they can update this file with Xcode, but that will take a little time. OpenRadarlink adds other static libraries/frameworks here. What if you add other static (non-dynamic) libraries/frameworks to your own foundation? Really? Framework projects, they will only quote, not praise? Fake? The frame is also linked to the final binary file. Upgrade from an earlier version If you upgrade from Mk6 or an earlier version and use it at the same time? Really? Static framework, and using Xcode before 4.2. 1, please run uninstall_legacy.sh to uninstall all the fixes before Xcode. Then run install.sh and restart Xcode. If you use Xcode4.3, just run install.sh and restart Xcode. Install by running the install.sh script in the real frame directory or the fake frame directory (or you can run both directories at the same time). Restart Xcode, and you are in the framework of the new project wizard &; See StaticiOS framework under the library (or fake Static iOS framework). To uninstall, run the unistall.sh script and restart Xcode. Create an iOS framework project Create a new project. Project type selection framework &; Static iOS framework under the library (or pseudo static iOS framework). Choice? Including unit testing? (optional). Add courses, resources, etc. To the target. Any header files to be used by other projects must be declared public. Go to the target's Build Phases page, copy the Headers item, and drag the header file that needs to be exposed from the project or private part to the public part. Compile your iOS framework, select the scheme of the specified target, and modify the running configuration of the scheme (optional). By default, the running configuration uses debugging, but you may want to use publishing when preparing for deployment. Compilation framework (no matter whether the target is an iOS device or an emulator, the same binary will be compiled, so it doesn't matter who you choose). Select your frame from the product. Show in Finder? . There are two folders under the build directory: (yourframework). Frame and (your frame). Embedded framework. If your framework only has code and no resources (such as pictures, scripts, xib, momd files of coredata, etc.). ), you can distribute (your framework). Framework for your users. If it also contains resources, it must be distributed. Embedded framework for your users. Why do you need an embedded framework? Because Xcode doesn't look for resources in static frames, if you distribute (your frame). Frame, all resources in the frame will not be displayed or available. Embedded framework is just an additional package outside the framework, including symbolic links of all resources of this framework. The purpose of this is to enable Xcode to find these resources. Using the iOS framework, the iOS framework is similar to the regular Mac OS dynamic framework, except that it is statically linked. Use a frame in your project, just drag it into your project. When including header files, remember to enclose the frame name in angle brackets instead of double quotes. For example, if Xcode cannot find the header files of MyFramework: #import may forget to declare them as public. Reference? Create an iOS framework project? Step five. There is no such product type. If you don't install the iOS common framework in Xcode and try to compile a common framework project (for? Really? Frame, isn't it? Fake? Framework), which will lead to the following error: compile for a specific product type' com.apple.product-type.framework.static', but there is no such product type for the' iPhone Simulator' platform? Really? IOS static framework, Xcode needs to make some changes, so in order to compile? Really? Static framework project, please install it in all development environments (users who use the framework do not need it, but only need it when compiling the framework). The selected run destination is invalid for this operation. Sometimes, Xcode will make an error and load the wrong active settings. First, try restarting Xcode. If the error still exists, Xcode will generate a bad project (due to a bug in Xcode4, this problem will appear in any type of project). If so, you need to create a new project and start over. Link warning When compiling a framework target for the first time, Xcdoe will report that the folder: LD: Warning: The directory of the option'-L/Users/MySelf/Library/Developer/XCode/Derived Data/MyFramework-CCHFOCJQIOGNAQRAESRXDYQCNE/Build/Products/Debug-iPhone OS' was not found. At this time, you can clean up and recompile the target, and the warning will be eliminated. The framework project and the application project can't find the core data momd, and Xcode compiles momd (managed object model file) in different ways. Xcode only creates a. mom file in the root directory, instead of creating a. mom directory (including VersionInfo.plist and. Mom file). This means that when instantiating the NSManagedObjectModel from the model of the embedded framework, you must use the. The mom extension is used as the URL of the model, not. Mom, extension. NSURL * modelURL =[[ns bundle main bundle]URLForResource:@ " my model " with extension:@ " mom "]; Unknown class my class in the interface generator file. Because static frameworks use static links, linker will eliminate all the code it thinks is useless. Unfortunately, the linker does not check the xib file, so if the class is referenced in xib instead of O-C code, the linker will delete the class from the final executable file. This is a linker problem, not a framework problem (this problem can also occur when compiling static libraries). Apple's built-in framework will not have this problem, because it is dynamically loaded at runtime, and the dynamic libraries existing in the firmware of iOS devices cannot be deleted. There are two solutions: ask the end users of the framework to turn off the linker optimization option by adding -ObjC and -all_load to other linker flags of their projects. Add a code reference to another class in the framework. For example, suppose you have a MyTextField class, which is eliminated by the linker. Suppose you still have a MyViewController, which uses MyTextField in xib, and MyViewController has not been eliminated. You should do this: in MyTextField: +(void)forceLinkerLoad_ {} In MyViewController:+(void) initialize {[MyTextfield Forcelinkerload _]; } They still need to add -ObjC to the linker settings, but they don't need to force all_load. The second method requires you to do more work, but it allows end users to avoid turning off linker optimization when using your framework (turning off linker optimization will cause the target file to swell). Unexpected file type' wrapper.cfbundle' in the frame. This problem occurred in the construction stage of the library? Fake? When the frame project is a workspace or subproject (? Really? Framework projects do not have this problem). Although this kind of frame project produces a correct static frame, Xcode can only see that it is a bundle from the project file, so it will issue a warning when checking the dependency and skip it in the linker stage. During the linking phase, you can manually add commands to make the linker link correctly. Add: -frameworkmyframewarning to other linker flags of projects that depend on your static framework, but this will not cause link failure. Unfortunately, the library is linked or not linked to the final framework, really? Frame and? Fake? Frame templates work differently when dealing with imported static libraries/frames. ? Really? The frame template adopts normal static library generation steps and will not link other static libraries/frames to the final product. ? Fake? Frame template adoption? Cheating? Xcode means that it is compiling an object file in a relocatable format. In the linking stage, just like compiling an executable file, all static code files are linked into the final product (although it will not check whether the target code is true). To achieve the image? Really? Frame has the same effect. You can only include the header file of the library /frame in your project, not the library /frame itself. Unrecognized selector in (a class with a category method) If your static library or static framework contains a module (only declared in the class code, not implemented by the class), the linker will get confused and remove the code from the binary file. Because there is no such method in the final generated file, when calling the method defined in this category, a? Unrecognized selector? Not normal. To solve this problem, add a? Fake? Class. The linker finds a complete O-C class and links the class code to the module. I wrote a header file LoadableCategory.h to reduce this workload: # import "Someencore class+myadditions.h" # import "loadable category.h" make _ categories _ loadable (Someencore class _ myadditions); @ Implement some concrete classes (myadditions)...@ end When using this framework, you need to add -ObjC to other linker flags set by Build. Unit tests crash before executing any code. If you create a static frame (or library) target in Xcode4.3, check it? Use unit tests? When you try to run a unit test, it will crash: thread1:exc _ bad _ access (code = 2, address = 0x0) 0 0x00000000-15 dyldbbootstrap: start (...) This is a bug of lldb. You can use GDB to run unit tests. Edit the scenario, select the test, and change the debugger from LLDB to GDB in the information tab.