Sharing fast code across multiple projects

So, we have several projects with common code, and they should remain compatible, at least with iOS7.

We are currently using local cocoapods to exchange codes between different applications. This has the disadvantage that all common code is placed in one group. In addition, the Cocoapods team explained why fast containers would not be available for iOS7 projects:

CocoaPods only supports Swift on OS X 10.9 and later, and iOS 8 and later.

That's why:

Swift is supported on OS X 10.9 / iOS 7 and later, as stated by Apple many times. There is no support for creating static archives with Swift. Dynamic frameworks are supported in all versions of OS X. Dynamic frameworks are not supported in iOS versions prior to 8:

ld: warning: built-in dylibs / frameworks only work on iOS 8 or later.

(Source: http://blog.cocoapods.org/Pod-Authors-Guide-to-CocoaPods-Frameworks/ )

Given this information, we want to try and share the code using the Cocoa Touch Framework -project.

What I've done:

  • In the workspace, create a new project -> Cocoa Touch Framework
  • Add / move quick code here and define the necessary functions / etc as public
  • For the main purpose of the assembly, add a new project as an "Inline Structure"
  • If you need to use classes from a specific library, use the import statement, where the target name of the assembly is the name of the module (in my case, import Cobra )

This seems to work, also on iOS7. Which is strange because everywhere on the Internet I read this warning so that the application does not start on iOS7 devices:

 embedded dylibs/frameworks only run on iOS 8 or later 

However, for us, this works great on our iOS 7 testing devices. Also, this concerns me:

enter image description here

The path to the structure is directly linked to my local DerivedData folder. I specifically did not select the DerivedData folder, I just added the proposed structure from Xcode and decided to capture it myself from my DerivedData folder. We are working on this project with several programmers.

TL; DR;

Before proceeding along this path and moving the code to this new setting:

  • Does this method of embedding a shared library cause problems for my team? (in other words: am I doing something wrong?)
  • Will this way of embedding libraries cause problems when sending apps to the App Store?
  • If necessary: ​​is there an alternative to sharing code between projects without just copying the code / files back and forth? I can’t believe that anyone else has not had this problem.
+8
xcode ios7 swift
source share
2 answers

Update 02-03-2015:

For code sharing, I recommend using git submodules, which require you to pass your code to a hosted repository, which can be open or closed.


Git Submodules

This is a way to distribute the code stored in the repository to anyone with access. This benefits that you can make changes to the repository, which other consumers can then choose to update their own submodule repositories. To be used as a project management source, git is required, and it also requires that the code be ported to a repository that consumers have access to.

To use the code as a submodule of git, you add the code repository to your managed git project with the command:

 git submodule add https://github.com/user/submoduleProject 

replacing https://github.com/user/submoduleProject with your own repository url.

After this has been added, you can use the commands:

 git submodule init 

and

 git submodule update 

to pull the code from the repository to the user's workspace.

If you want to add any changes or updates to the submodule, you can do this and push it to the repository. Users can then update their code with git submodule update to get the latest changes.

More information on git submodules can be found in the official documentation.

Hope this helps.


The application will not be accepted by the application loader or Xcode when sent to the App Store if the dynamic infrastructure is used in an application that supports anything less than iOS 8. This is sad because, as you said, this works for iOS 7 when testing on device.

The best way I can share my code with your team is to transfer the code folder and include it in the project, rather than include a dynamic structure. If you want the spaces between the names to be consistent, so that in the future you can use the dynamic structure and switch from iOS 7, I recommend using the structure around public methods and classes to get the namespace. For example:

 public struct MyFrameworkName { public func doSomethingAmazing() { // Code... } public class DecentClass: NSObject { // Code.. } public var terribleString: String } 

This will allow you to call methods inside the rest of the application in the same way as using the Dynamic Framework

 var myObject = MyFrameworkName.DecentClass() myObject.doMethod() MyFrameworkName.doSomethingAwesome() MyFrameworkName.terribleString = "HEY"; 

In response to your concern about linking to a structure directly from the derived data directory, this is usually the wrong approach.

Ideally, you copy the framework into the project directory and then link it to this version. This allows you to distribute the project’s source directory to other people, and the structure will remain in the right place relative to the project’s source folder.

Hope this helps answer your question.

+6
source share

git submodules will work. They can be a pain for work.

If you don’t want to use them, I applied a workaround that uses the second “dummy” project with cocoapods to output the Swift code without having to use Framework.

https://medium.com/@mishagray/how-to-use-swift-cocoapods-and-still-support-ios-7-0-f9dc29b3628b

0
source share

All Articles