Xcode Workspace - Not finding imports from framework development pod - ios

I've set up a workspace with two Swift projects in it: one a framework I'm developing, the other a demo app for the framework.
Podfile looks like this:
platform :ios, '9.0'
workspace 'foo.xcworkspace'
target 'framework' do
project 'framework.xcodeproj'
end
target :'demo' do
project 'demo/demo.xcodeproj'
pod 'framework', :path => 'framework.podspec'
end
the .podspec file looks like this:
Pod::Spec.new do |s|
s.name = 'framework'
s.authors = { "foo author" }
s.version = '0.1.0'
s.summary = 'foo summary.'
s.homepage = 'foo homepage'
s.platform = :ios, '9.0'
s.license = {
:type => "Proprietary",
:file => "LICENSE"
}
s.source = {
:git => 'https://url.to/foo.git',
:tag => s.version.to_s
}
s.source_files = 'framework/framework/**/*.{swift,h,m}'
s.requires_arc = true
s.weak_framework = "XCTest"
s.pod_target_xcconfig = {
'FRAMEWORK_SEARCH_PATHS' => '$(inherited) "$(PLATFORM_DIR)/Developer/Library/Frameworks"',
}
end
After running pod install, Xcode/AppCode can still not see the classes from the framework project. So if I add a manual import to a class in the demo app and try to compile, it fails with:
Error:(13, 21) use of undeclared type 'FooClass'
What do I have to do to properly have the demo app project see the classes from the framework project generated pod?

Try using inherit! :search_paths on the demo target
This means they don't get their own copies of the pods but can see they exist via the header files.
platform :ios, '9.0'
workspace 'foo.xcworkspace'
target :framework do
project 'framework.xcodeproj'
end
target :demo do
inherit! :search_paths
project 'demo/demo.xcodeproj'
pod 'framework', :path => 'framework.podspec'
end
untested but perhaps worth a shot

If you install a Cocoapod don't use the file with .xcodeproj to open your project anymore, but the newly created .workspace in the same folder.

I finally resolved this issue:
Make sure the min. required iOS is defined in Podfile, e.g.:
platform :ios, '10.0'
Add any third-party pods also to the podspec file, e.g.:
spec.dependency 'Alamofire', '~> 4.5'
spec.dependency 'Serpent', '~> 1.0'
If doing pod install without the use_frameworks! it will mess up some things (see this answer: ld: framework not found Pods). So in between I got these invalid Pod xconfigs that I had to delete and then do a clean and pod install.
Make sure to build the framework project at least once and then the demo source should find the import to the framework pod name!
Make sure that all classes are correctly added to their target, especially classes in the test target should not have been added to the app target accidentally.
After all is said and done, having worked with a multitude of IDEs and development technologies, Xcode and Cocoapods can only be summed up as one giant clusterf*** of an accident!

Related

Using the framework from one target as a pod in another target locally

I'm having trouble using a framework I wrote in other targets (the same project) using modular imports. I'm using Cocoapods. I'm getting Could not build module: errors while trying to import the module using modular imports (#import CMPComapiFoundation;). I attach a link to the repo for more information.
I did try both local (:path =>) and remote (:git =>) ways of pulling the SDK in Podfile, none of which seems to work. It's worth noting that if added via Cocoapods in a separate project, the code compiles and the SDK can be imported.
SDK's .podspec file:
Pod::Spec.new do |s|
s.name = 'CMPComapiFoundation'
s.version = '1.2.2'
s.license = 'MIT'
s.summary = 'Foundation library for connecting to and consuming COMAPI services'
s.description = <<-DESC
# iOS SDK for Comapi
Client to connect your iOS application with [Comapi](http://comapi.com/) services and add it as a channel to our cloud messaging platform. Written in Objective-C.
For more information about the integration please visit [the website](http://docs.comapi.com/reference#one-sdk-ios).
DESC
s.homepage = 'https://github.com/comapi/comapi-sdk-ios-objc'
s.author = { 'Comapi' => 'support#comapi.com' }
s.source = { :git => 'https://github.com/comapi/comapi-sdk-ios-objc.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/comapimessaging'
s.ios.deployment_target = '10.0'
s.requires_arc = true
s.source_files = 'Sources/**/*.{h,m}'
s.resources = []
s.dependency 'SocketRocket'
end
And here's the Podfile I'm using for the entire project:
platform :ios, '10.0'
use_frameworks!
def shared
pod 'CMPComapiFoundation', :path => '/Users/dominik.kowalski/Documents/comapi-sdk-ios-objc'
pod 'JWT'
end
target 'CMPComapiFoundation' do
pod 'SocketRocket'
end
target 'CMPComapiFoundationTests' do
shared
end
target 'ComapiFoundationSample' do
shared
end
target 'ComapiFoundationSample-Swift' do
shared
pod 'SnapKit'
end
I expect the test and sample targets to import the modules and compile the code.
Okay I managed to fix it myself. Some header files were missing Target membership, but Xcode gave me misleading hints.

Custom cocoapod not finding swift file

I'm trying to create a custom Cocoapod to handle all of my networking calls for my iOS application. The issue that I am having is that some of my files that should be part of my new Cocoapod/framework are not found when I try to reference them in code.
I followed this tutorial https://www.raywenderlich.com/5823-how-to-create-a-cocoapod-in-swift and I successfully created the Cocoapod .xcworkspace project (named: ios-oauth2-rest-template) and added it to bitbucket and created a private PodSpec repo on bitbucket as well (named: KPodSpec) (two separate repos).
I was able to make it through the tutorial but I got stuck on the part 'Using Your New CocoaPod.' I was able to run the following commands to add the Cocoapod to my PodSpec repo:
pod repo add KPodSpecs [Your RWPodSpecs Git URL]
pod repo push KPodSpecs ios-oauth2-rest-template.podspec
When I try to use my new pod in an existing project (named: KApp) some of the files that are in my Cocoapod are able to be referenced while others will not autocomplete even after I import ios_oauth2_rest_template.
I'm not sure if I'm just missing the framework for ios-oauth2-rest-template inside my KApp project. Any help would be much appreciated.
KApp Podfile:
# Uncomment the next line to define a global platform for your project
platform :ios, '12.0'
source 'https://github.com/CocoaPods/Specs.git'
source 'https://bitbucket.org/kpodspecs.git'
target 'KApp' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for KApp
target 'KAppTests' do
inherit! :search_paths
# Pods for testing
end
target 'KAppUITests' do
inherit! :search_paths
# Pods for testing
end
pod 'LBTAComponents'
pod 'SwiftyJSON', '~> 4.0'
pod 'TRON', '~>4.0'
pod 'ios-oauth2-rest-template', '~> 0.0.1'
end
ios-oauth2-rest-template podspec:
Pod::Spec.new do |s|
# 1
s.platform = :ios
s.ios.deployment_target = '12.0'
s.name = "ios-oauth2-rest-template"
s.summary = "My summary here"
s.requires_arc = true
# 2
s.version = "0.0.1"
# 3
s.license = { :type => "Proprietary", :file => "LICENSE" }
# 4 - Replace with your name and e-mail address
s.author = { "My Name" => "myemail#email.com" }
# 5 - Replace this URL with your own GitHub page's URL (from the address bar)
s.homepage = "https://bitbucket.org/myStuff"
# 6 - Replace this URL with your own Git URL from "Quick Setup"
s.source = { :git => "https://bitbucket.org/myStuff.git",
:tag => "#{s.version}" }
# 7
s.framework = "UIKit"
s.dependency 'Heimdallr', '~> 3.6.1'
# 8
s.source_files = "ios-oauth2-rest-template/**/*.{swift}"
# 9
#s.resources = "RWPickFlavor/**/*.{png,jpeg,jpg,storyboard,xib,xcassets}"
# 10
# s.swift_version = "4.0"
end
ios-oauth2-rest-template Podfile:
# Uncomment the next line to define a global platform for your project
platform :ios, '12.0'
target 'ios-oauth2-rest-template' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
use_frameworks!
# Pods for ios-oauth2-rest-template
pod 'Heimdallr', '~> 3.6.1'
target 'ios-oauth2-rest-templateTests' do
inherit! :search_paths
# Pods for testing
end
end
Thanks in advance. I have scoured the internet to no avail as to why this could be happening and I am stumped since I don't have that much experience with CocoaPods in the first place.
UPDATE
Here are some screenshots
The Pods section of the KApp, to show some of my classes. When I try to use ApplicationUtils it works just fine and autocompletes, but when I try to use BaseClass it cannot seem to find it.
Build phases under settings to show that all 30 files are under compile sources. The 30 files match the 30 files from the ios-oauth2-rest-template Xcode project. The 31st file is ios-oauth2-rest-template-dummy.m.
Image showing the folder structure of ios-oauth2-rest-template Cocoapod project.
Thanks to #balazs630, I was able to solve the problem. I had to make sure my access control was set to public or open in order to access them. Looking back at my code, ApplicationUtils was a public class and BaseClass had no designation, so it was by default internal, which according to the docs:
Internal access enables entities to be used within any source file
from their defining module, but not in any source file outside of that
module.
For anyone with a similar problem, check to make sure your access control is set appropriately. Here are some sources to familiarize yourself with access control in Swift:
https://medium.com/#abhimuralidharan/swift-3-0-1-access-control-9e71d641a56c
https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html

Local CocoaPods interfering with other pods

I'm writing a Swift Framework and a Swift iOS Application and I'm trying to use Cocoapods to add my framework into my app and other sdks as well.
Here is my podspec for my swift framework
Pod::Spec.new do |s|
s.name = "InfraCocoa"
s.version = "0.0.1"
s.summary = "A short description of InfraCocoa."
s.license = "MIT"
s.author = { "" => "" }
s.platform = :ios
s.ios.deployment_target = "7.0 "
s.source_files = "Classes", "Classes/**/*.{swift,h,m}"
end
My pod podfile for my iOS app
target 'CocoaProjectTest' do
pod 'InfraCocoa', :path => '~/Documents/workspaces/CocoaPodsTesting/Infra/InfraCocoa'
pod 'CrashlyticsFramework', '2.2.5.2'
pod 'GoogleTagManager', '3.09'
pod 'Google-Mobile-Ads-SDK', '7.0.0'
pod 'Facebook-iOS-SDK', '3.23.0'
pod 'AFNetworking', '2.5.1'
end
Now at first if I run the 'pod install' or 'pod update' everything works fine. The problem is when I try to build in Xcode(6.1.1). I get a compile error saying stuff like this
"_sqlite3_close", referenced from:
-[TAGDataLayerPersistentStoreImpl closeDatabase] in libGoogleAnalyticsServices.a(TAGDataLayerPersistentStoreImpl.o)
(maybe you meant: _fbdfl_sqlite3_close)
After a few google searchs I found it is because my GoogleTagManager is missing the libraries 'libz.dylib' and 'libsqllite3.dylib' in it's 'Link Binary With Libraries'. I can manually add them and it will compile although this is not ideal.
I decided to test without the following line in my podfile and it compiles
pod 'InfraCocoa', :path => '~/Documents/workspaces/CocoaPodsTesting/Infra/InfraCocoa'
I figured it was probably because of a conflict in library version but this InfraCocoa framework is completely clean and empty (did a File-> New-> Project -> CocoaTouch Framework).
Any ideas? (the app project too is empty and clean)
I think you could have overridden the GoogleTagManager.podspec in your PodFile and simply add the missing libraries in your modified version of the file.
something like:
pod 'GoogleTagManager', :podspec => './GoogleTagManager.podspec.json'
and in the podspec:
"libraries": ["GoogleAnalyticsServices", "sqlite3", "z"],
Seems to be working with cocoapods 0.36.rc.1

Using dependency in swift module (framework)

I am trying to create a swift module (Cocoa Touch Framework) with reusable code inside the environment set up by cocoa pods which includes third party libraries written in Objective-C (namely here Restkit).
Unfortunately I am not able to use Restkit in the module I create.
Here's what I did to create the module:
File -> New target: Cocoa Touch Framework, Language: Swift, Project: MyProject, Embed in Application: MyProject
In the "Info" tab of the project settings in the "Configurations" section I define the Pods.debug and Pods.release xcconfig file for my newly created target.
In the header file, which Xcode automatically created for me, networkModule.h, I add the following line:
#import <RestKit/RestKit.h>
Result: When trying to compile I get the error "include of non-modular header inside framework module 'networkModule'"
I have set the flag for "Allow Non-modular Includes in Framework Modules" to YES in the build settings for the Project Target and the Module/Framework target.
I went to the Cocoa pod project and have tried setting the visibility of the RestKit.h Header file to "Public" in the target membership (which of course is not a good solution to mess with the cocoa pods environment)
I am not able to compile. I still get the same error.
Is it possible in the first place to create a Cocoa Touch Framework with dependencies to a cocoa pod managed framework?
Btw. My first idea of creating a private cocoa pod didn't work out as well, as it doesn't seem to be supported, although I am using the prerelease of cocoa pods 0.36 with support for swift.
You should be able to make your won private Pod. You just need to make a podspec for it. Here is an example of one.
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 have to do pod init open your podfile that was just created 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 stated twice the second is commented out. If you uncomment it and comment out the first then do pod install in your projects folder from the terminal. This will make a DevelopmentPod which is a pod that is local. This way you can make changes to the pod locally within Xcode. No switching and pod installing every time you make a change.
You will import the pod just like any other by putting
import Commons not #import <Commons/Commons.h> That is how you do it in Objective C not Swift
Once you have a working version commit it to git hub and point your project to the the github version.
Hope this helps.

Attempting to add OpenTok 2.3 as a local cocoapod

I need to add OpenTok 2.3 to a project that uses cocoapods, however only 2.1.7 is present in the pods repository or on github, so I have downloaded the framework locally. My folder structure looks something like this:
project-
|
Podfile
project.xcodeproj
frameworks/
|
OpenTokSDK-WebRTC.podspec
OpenTok-iOS-2.3.0/
|
OpenTok.framework
And the contents of the OpenTokSDK-WebRTC.podspec file is:
Pod::Spec.new do |s|
s.name = 'OpenTokSDK-WebRTC'
s.version = '2.3'
s.authors = 'TokBox'
s.summary = 'The OpenTok iOS SDK lets you use OpenTok video sessions in apps you build for iPad, iPhone, and iPod touch devices.'
s.homepage = 'https://github.com/opentok/opentok-ios-sdk-webrtc/'
s.license = {
:type => 'Apache'
}
s.source = {
:path => './OpenTok-iOS-2.3.0'
}
s.platforms = {
:ios => '5.0'
}
s.source_files = 'Opentok.framework/Versions/A/Headers/*.h'
s.resources = 'Opentok.framework/Versions/A/Resources/opentok.bundle'
s.frameworks = [
"Opentok",
"UIKit",
"CoreMedia",
"CoreVideo",
"CoreAudio",
"CoreTelephony",
"CFNetwork",
"AVFoundation",
"SystemConfiguration",
"Security",
"QuartzCore",
"AudioToolbox",
"OpenGLES",
"MobileCoreServices"
]
s.libraries = [
"stdc++",
"z"
]
s.xcconfig = {
:FRAMEWORK_SEARCH_PATHS => "\"frameworks/OpenTokSDK-WebRTC/\""
}
s.preserve_paths = 'Opentok.framework'
s.requires_arc = false
end
The relevant line in the Podfile is
pod 'OpenTokSDK-WebRTC', :path => "frameworks"
When I run 'pod install' everything appears to run fine, however there is no OpenTokSDK folder in the Pods directory and I get a file not found error in xcode when trying to include . Does anyone know what I am missing?
Thanks for your help.
As I found on their Blog Here is the link new-in-ios-10-the-best-webrtc-apps-yet. you need to Add pod 'OpenTok' in your pod file. So updated version of talk box is Added in your Project. and Now Open your xcworkspace file inplace of xcodeproj file .
Here is my Podfile ,
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'ProjectName' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
pod 'AFNetworking', '~> 3.0'
pod 'OpenTok'
# Pods for ProjectName
target 'ProjectNameTest' do
inherit! :search_paths
# Pods for testing
end
target 'ProjectNameUITests' do
inherit! :search_paths
# Pods for testing
end
end
Note :- If you are using Swift then please uncomment # use_frameworks!
After updating your pod file enter "pod install" command in your terminal. and Tokbox will successfully install in your project.

Resources