Scenario Description:
-Before doing the app, use the SWIFT Framework language, mixed programming, connotation of a few OC code.
-Requires the app's overall functionality to be packaged into a static library, fully ported to another app, using the OC language, based on the REACTIVECOCOA framework.
-----------------------------------------Pack a piece -----------------------------------------
Implementation steps:
First, new Project-framework&library-cocoa Touch framework,next language Choice Swift
When Setup is complete, you will see a xxx.h and Info.plist file that is generated by default.
The Xxx.h file has the following functions:
1. Provide an import reference to the OC file referenced in the SWIFT project, note that it must be exposed to public in the headers of build phrases before referencing it here.
2, provide to the third party file import, the third party management here, still use Pods management, the following will be described in detail.
The above two complete the effect,
Info.plist A file acts like a plist file of a normal project, and is used to define or add some attributes.
Add files, you can create your own, or copy from other projects.
Note here: Because the Packaging Class library project is not a complete project engineering, so there is no appdelegate and other files, so involved in these files to additional processing, or change the code, or appropriate changes in functionality.
Note: If the project has bridged files, it cannot be copied, otherwise the compilation does not pass.
See step five for a reason.
Three, if there is a third-party class library Reference, add a third-party library file, there are a few points to note: (No can skip)
A, third-party libraries are still managed using pods, adding the same methods as normal projects.
b, when quoting, we need to add "use_frameworks! "To tell the pod to generate a dynamic library file framework type, the benefit is that when a formal project is used in this class library, if the two third-party libraries have referential conflicts, you can remove the dependent libraries introduced by this class library based on the conflicting class library.
But sometimes a third-party class library has only. A type, what should I do?
Workaround: If the third-party library has only the. A type, you will need to manually copy the library files to the project, not through the pod, otherwise you can not find the file when adding import to the header file in step 1, thus error.
Four or more three completed, the basic prototype of the library has been equipped with the following:
Here comes the problem of a resource file, compared to the processing of slices, video, audio, etc.
The practice of the previous normal project may be this way,
1: Direct with Assets.xcassets
2: New resources folder, storing pictures
But here, one thing to note:
For 1, this is not valid, we can create a new bundle file, the image will be ported over.
For 2, we can directly modify the add suffix locally. Bundle
Then a key point is the path problem: Because of the resource file of the class library, when we use the official project, find the path file is not for the project, but for the path of the class library, so we refer to the resource file path is changed, and the other xib in the class library, The storyboard file reference path needs to be changed.
Resourcerooturl is the xib, storyboard file prefix path.
Resourceimagesrooturl is the image file prefix path. (need to add a layer of/images.bundle/)
How did this path come about?
frameworks/xxxx.framework/where XXXX is the name of the class library you created.
Reference reference:
Five, the file is basically added, you can try to build a bit
In theory, as long as the class library default Xxx.h file, OC header files and third-party header files are normally referenced, there will be no problem.
And the general error, but also because there is no good reason.
If the project is a pure Swift file, here the Xxx.h file only needs to be imported into the third-party header file.
======================= here to explain why the xxx.h file is doing this: =================
Because normal our Swift project, if need to introduce OC file, we must through a bridge file to handle the conversion between the two, and when we create a new class library, the class library is to prohibit the existence of this file, even if you add, will always compile, but can not be packaged.
So the xxx.h header file generated by default for this class library is used here.
We can use this file to achieve the conversion between the two, if you must first expose OC's. h, or even if you import, will be an error can not find the. h file.
(There is a problem, if there are too many OC files, there is a lot of exposure here, and there are too many, one is not beautiful, the second is that the following project references to the library are able to see these files.) So, can not pass a file, to load all these files, achieve only need a file to expose the effect of the line, someone realized the Welcome to guide, not very grateful. )
Six, compile through, see here
Inside the red box is the framework package that we finally get.
Right-clicking on a local view will see this class of libraries and the corresponding dependent third-party packages, which are needed later in the other project references.
PS: If you do not refer to a third party, you only need this type of library package.
-----------------------------------------Citation-----------------------------------------
1, we create a new empty project, because of my business needs, here the Engineering language choice OC.
2. Create a new framework folder and copy all the previous framework packages into the folder.
3, in the project Targets-general-embeddedbinaries add frameworks package
4, since my class library package is based on Swift, where OC is used, you must set a property:
5, because our own project has its own third-party library Reference, if you find that there is a conflict between the two or repeated references, resolved as follows:
A: If the pod is within the reference, there is no callout use_frameworks! Let's add the phrase first, and pod update, the third-party class library that keeps the references on both sides is the framework type.
B: Remove the duplicate class library you just added, such as AFN.
The pit I encountered when referencing the integration is as follows:
================================== Error 1:==================================
Dyld:library not loaded: @rpath/afnetworking.framework/afnetworking
This is because the library itself is referenced only by reference to the previous class library itself,
Workaround:
Method 1:
Method 2:
Follow my references-step 3 to do, in general, add all, will not report this problem.
================================== Error 2:==================================
Dyld:library not loaded: @rpath/libswiftcore.dylib
Workaround:
Follow my references-step 4 to do this and set the property to Yes.
================================== Error 3:==================================
Unknown class in Interface Builder file .... image not found, etc.
Workaround:
Http://www.cnblogs.com/yajunLi/p/5980560.html
================================== Error 4:==================================
Load Storyboard or Xib crashes
Workaround:
is because the packaging of the local reference file path is not changed, you need to add the class library prefix path, see packaging-step four.
If you have any other questions, please leave a message.
This article concludes.
Record Swift complete Project packaging framework, embedded in OC project use