How to use YouTube iOS player helper with use_frameworks! with CocoaPods

2.3k views Asked by At

As the question states, I'm trying to use this module in my Swift project using the use_frameworks! option on my Podfile. Like so:

platform :ios, "8.0"
source 'https://github.com/CocoaPods/Specs.git'

use_frameworks!

pod 'youtube-ios-player-helper', '~> 0.1.3'
pod 'ReactiveCocoa', '3.0-beta.6'
pod 'Moya'
pod 'Moya/Reactive'

I have checked the Pods project and it has a framework called youtube_ios_player_helper.framework since - is an invalid character for the name. But when I add import youtube_ios_player_helper to my Swift file I get an error saying it does not exist.

I must say that I have some Obj-C code in my project and because of this I also have a bridging header file in the project.

2

There are 2 answers

1
JAL On

Make sure you're adding the library to the correct target.

My Podfile:

platform :ios, '8.3'

target 'MyApp' do
    use_frameworks!
    pod 'youtube-ios-player-helper'
end

ViewController.swift:

import UIKit
import youtube_ios_player_helper

class ViewController: UIViewController {

    // ...

    override func viewDidLoad() {
        super.viewDidLoad()

        let myView = YTPlayerView()

        // ...
    }

    // ...

}

If the pure swift import import youtube_ios_player_helper doesn't work, adding #import "YTPlayerView.h" to your application's bridging header should have the same effect of bridging the YouTube helper class to Swift.

0
JAL On

Answer by the OP in the comments on their question:

It turns out the problem was in the Pods configuration. It was not being included in the project because of missing architectures. I had to turn off "Build only target architecture" for Debug mode. The code has so many warnings that I missed this one. Legacy code in Swift, that's a new one for me!