Using a dependency in a fast module (framework)

I am trying to create a quick module (Cocoa Touch Framework) with multiple code inside an environment configured using cocoa pods, which includes third-party libraries written in Objective-C (namely Restkit here). Unfortunately, I cannot use Restkit in the module I am creating.

Here is what I did to create the module:

  • File → New target: cocoa Touch Framework, language: Swift, project: MyProject, built-in application: MyProject

  • On the "Information" tab of the project settings in the "Configurations" section, I define the Pods.debug and Pods.release xcconfig file for my newly created purpose.

  • In the header file that Xcode automatically created for me, networkModule.h, I add the following line:

    #import <RestKit / RestKit.h>

Result: when I try to compile, I get the error message "inclusion of a non-modular header inside the frame module" networkModule "

I set the “Allow non-modular inclusions in structural modules” flag to “YES” in the build settings for the project target and target module / structure.

I went to the cocoa pod project and tried to set the visibility of the RestKit.h header file to "Public" in the target membership (which, of course, is not a good solution for riots with the cocoa pods environment)

I can not compile. I still get the same error.

Is it possible to first create a cocoa Touch Framework with dependencies with a cocoa managed pod framework?

Btw. My first idea of ​​creating a private cocoa pod did not work either, since it does not seem to be supported, although I am using cocoa pods 0.36 pre-release with quick access support.

+6
source share
1 answer

You should be able to make your private pod won. You just need to do podspec for this. Here is an example of one of them.

Pod::Spec.new do |s| s.name = "Commons" s.version = "1.0.0" s.summary = "Common code for my iOS projects." s.license = {:type => 'Commercial', :text => "Copyright (c) Dan Leonard(Or Your Name?). All rights reserved." } s.source = { :git => "https://github.com/PATHTOPOD", :tag => s.version.to_s } s.homepage = "https://github.com/PATHTOPOD" s.requires_arc = true s.ios.deployment_target = '9.0' s.subspec 'Core' do |ss| ss.source_files = '*.swift' end s.subspec 'Menu' do |ss| ss.source_files = 'Menu/*.swift' ss.resources = ['Menu/*.storyboard', 'Menu/*.xcassets'] ss.dependency 'Alamofire' end end 

Then inside your project you just need to make pod init open the created subcoder and add this

 source 'https://github.com/CocoaPods/Specs.git' xcodeproj 'YOURPROJECT.xcodeproj' platform :ios, '9.0' use_frameworks! pod 'Commons', git: 'https://github.com/PATHTOPODPROJECT' #pod 'Commons', :path => '/Users/YourUser/Path/To/Project/commons' pod 'KeychainSwift' pod 'SQLite.swift', git: 'https://github.com/stephencelis/SQLite.swift.git' 

Now in this example, Podfile Commons is declared twice, the second is commented out. If you uncomment it and comment out the first, then pod install in the project folder from the terminal. This will make DevelopmentPod, which is local. This way you can make changes to the POD locally in Xcode. Without switching and installing pod every time you make changes.

You import the module just like any other module by placing

import Commons not #import <Commons/Commons.h> So you do it in Objective C not Swift

Once you have a working version, copy it to the git hub and point your project to the github version.

Hope this helps.

0
source

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


All Articles