Fast Static Library

An attempt to create a utility project that is used in conjunction with my company's iOS applications. I did this at a previous job, but it preceded Swift. I obviously would like to keep the whole implementation in quick, not Obj-C.

I tried the cocoapod route using this guide , but there are problems with the build there before I can even start using my utility code in the main project.

Now I'm trying to use only the "Cocoa Touch Static Library", whose language is Swift, and still have no luck. I imported the entire .xcodeproj file into my workspace. At the moment, I have only one .swift file, as well as the header file created by Xcode. My project is called IosUtilsTest .

In particular, my test file uses:

 extension UIBarButtonItem { class func flexible() -> UIBarButtonItem { return UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: nil, action: nil) } } 

And in my application:

 import IosUtilsTest .... toolbar.items = [UIBarButtonItem.flexible(), centeredButton, UIBarButtonItem.flexible()] .... 

I get a compiler error that flexible does not exist.

I tried to include both <IosUtilsTest/IosUtilsTest-swift.h> and <IosUtilsTest/IosUtilsTest.h> in my bridge header.

Basically, it looks like the extension is not included in the assembly. FWIW - I remember that there was a problem with categories requiring a special build flag, so I tried this only with the class I was trying to create, and that was the same basic error.

+5
source share
1 answer

We have a project that includes many fast framework modules that are all built into the application, so I should be able to provide some help.

First, you want to create the Cocoa Touch Framework as a project type.

The first one that got me was that everything within the structure should be declared public, since it is internal by default. Well, at least the parts of the API that you want to open to clients. Therefore use:

 public extension UIBarButtonItem { class func flexible() -> UIBarButtonItem { return UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: nil, action: nil) } } 

You no longer have to do it, just import your module into a .swift file, and also enable the framework in a binary connection to the libraries.

We also tried cocoapods and spent a lot of time on it to no avail. A lot of build errors, so we just refused and used the Git submodules. You are right, this is not quite as good as installing cocoapod, but it works great for us, just a little overhead. You can mark your submodules as "automatically extracting" in .gitmodules if you wish.

One thing that should be careful with Cocoa pods, if you use it, is that for now, your entire application should be built using the same version of Xcode. Therefore, if you have a module that is built with an older version of Xcode and then placed in Cocoa pods, you will need to make sure that you rebuild it when you upgrade Xcode. This is due to the fast lead time that is packaged with the assembly - see the Apples Swift Blog for more details.

+6
source

Source: https://habr.com/ru/post/1207753/


All Articles