Ian Newson Ian Newson - 1 year ago 113
iOS Question

CocoaPods: Mix ObjectiveC and Swift

I'm working on a custom CocoaPod to be deployed privately. Most of the code in this pod is existing code written in ObjectiveC.

All of the ObjectiveC code is perfectly accessible from both ObjectiveC and Swift in implementing projects, but I don't seem to be able to access any of the Swift code from either language in the implementing projects. I would like to be able to use and update the existing ObjectiveC code, but use Swift for anything new and for Swift specific features.

How can I use Swift code from a primarily ObjectiveC CocoaPod in Swift files in my implementing project?

My CocoaPod is called XibisFrameworkPod, and I've tried using the following import statements in my implementing project Swift files:

import XibisFrameworkPod
import XibisFrameworkPod.Swift

Here's my redacted podspec file:

Pod::Spec.new do |s|
s.name = 'XibisFrameworkPod'
s.version = '0.1.0'
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

s.ios.deployment_target = '7.0'

s.source_files = 'XibisFrameworkPod/Classes/**/*'

Answer Source

Turns out I was just missing the public modifier on the class/function declarations:

public class SomeClass : NSObject
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download