I'm creating a pod in swift to use with cocoapods, but I'm having a strange problem when trying to use it. My pod is downloaded normally after 'pod install' and I can import it via 'import MyPod'. So far so good, but when I try to access my classes in the pod, I get the message
"Use of undeclared type 'NameOfTheClassIwantToUse'".
If i go to my pod folder in Pods project, all the files are there, but I cannot use it. I also noticed when I go into the import 'MyPod' with command+click I can see just few imports instead of all my classes, like:
import MyPodProjectName
import MyPodProjectName.Swift
import Foundation
import UIKit
public var MyPodProjectNameVersionNumber: Double
While other imports has all the classes that are supposed to be available upon importing.
Does anyone has a clue on what am I missing here?
The Podfile is a specification that describes the dependencies of the targets of one or more Xcode projects. The file should simply be named Podfile . All the examples in the guides are based on CocoaPods version 1.0 and onwards.
The Pod file is located in the folder of your app. If there is no Pod file yet type the command: pod init in the terminal first. Make sure to cd into your app folder first. If this throws errors try to rebuild it by pressing on your keyboard Command+B.
Be sure to declare you class as public, as stated here
https://guides.cocoapods.org/making/using-pod-lib-create
As stated there:
It's worth mentioning here, as this catches people quite often, a Swift library needs to have its classes declared as public for you to see them in your example library.
So, just declare namespace "public" on you classes and you are good to go
I had the same problem, and this worked for me!
Yes you need to declare your class, methods and relevant variables as public
and don't forget to import your module on top of the class you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With