OSX and iOS common fast module

I created a quick Cocoa Touch Framework project called TestLib , then I added a new target for Cocoa Framework called TestLibOSX . When I use the framework in the iOS application, it works without any problems, but when I create the OSX console application, Xcode complains that it could not find the TestLibOSX module. Did I miss something?

PS This is not the same :)

EDIT: It seems like it should be possible since I see Lister this way.

+6
source share
2 answers

If you want to create a single binary file of a dynamic structure, follow these steps (as described in http://colemancda.imtqy.com/programming/2015/02/11/universal-ios-osx-framework/ ):

1. Change the valid project architectures and supported platforms.

It should also change the valid architectures of your platform and test unit and the supported platforms. If not, manually change them to inherit from the project build settings.

Step one

  • Base SDK: I recommend OS X, but it will work with iOS. Please note that with iOS as the base SDK, the My Mac target is split into 3 different targets.

  • Supported platforms: macosx iphoneos iphonesimulator

  • Valid architectures: arm64 armv7 armv7s i386 x86_64

2. Change the search paths for the Unit Test package.

Step two

  • Path search paths: $(inherited) @executable_path/Frameworks @loader_path/Frameworks @executable_path/../Frameworks @loader_path/../Frameworks

  • Search Ways: $(SDKROOT) $(inherited)

This will allow you to import it as import MyFramework instead

 #if os(iOS) import MyFramework #else import MyFrameworkOSX #endif 
+3
source

Well, universal frameworks are really a pain. Not only for iOS and OSX, but only for iOS, as you need 2 frameworks: one for the simulator and one for the devices. How you work with iOS is an โ€œaggregateโ€ goal. I believe that the same path can be used to integrate the OS X target.

When you create the framework, you get the folder.framework (lego block). There are 2 very important things:

  1. Executable file
  2. Folder "Modules"

In both of these cases, you must have an implementation to support all the architectures that you want to support. If you want to create your own frameworks separately and want to combine them together, you will have to do the following:

  1. Take both executables and merge them using the lipo command.
  2. Ensure that all files in the Modules folder are moved together.

In practical terms, this is a mess, so here's what I do!

  • First I build the framework. They may have different goals in the same project, but usually the same name helps. Only for iOS there is only one framework, so just one goal is enough.
  • Then I add the Aggregate target, it will help to create several assemblies for different architectures.
  • By clicking on the project name and then on the Aggregate target, I go to "Build Phases" and click on a small plus to add the "Phase of the new startup script".
  • There I copy and paste the code into this GIST.
  • Finally, changing your scheme to Aggregate target and creating it will result in the necessary merging, and you will get a universal framework structure.

The scenario is quite simple, and after playing a little, Iโ€™m sure that it can be changed by adding OSX support to it. I hope this points you in the right direction :)

Scenario Content:

 #!/bin/sh UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal # make sure the output directory exists mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" # Step 1. Build Device and Simulator versions xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build # Step 2. Copy the framework structure (from iphoneos build) to the universal folder cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/" # Step 3. Copy Swift modules (from iphonesimulator build) to the copied framework directory cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/." "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule" # Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}" # Step 5. Convenience step to copy the framework to the project directory cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}" # Step 6. Convenience step to open the project directory in Finder open "${PROJECT_DIR}" 
+1
source

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


All Articles