Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" => "[email protected]" }

# 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. The Pods section of the KApp, to show some of my classes.

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. Build phases under settings to show that all 30 files are under compile sources.

Image showing the folder structure of ios-oauth2-rest-template Cocoapod project. Image showing the folder structure of ios-oauth2-rest-template

like image 965
nviens Avatar asked Nov 24 '25 19:11

nviens


1 Answers

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
like image 176
nviens Avatar answered Nov 27 '25 10:11

nviens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!