Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating pod, use of undeclared type for my pod classes

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?

like image 499
Guilherme Avatar asked Mar 04 '16 21:03

Guilherme


People also ask

What is POD file in Xcode?

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.

How do I add a pod to Swiftui?

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.


2 Answers

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!

like image 86
paolaccio Avatar answered Oct 17 '22 22:10

paolaccio


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.

like image 2
isuru Avatar answered Oct 18 '22 00:10

isuru