Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Installing and Using CocoaPods for iOS

Paul M
Paul M
16,370 Points

What do I do with CocoaPods in Swift 3?

I keep trying to follow his instructions and it didn't work with Swift 3, if I use Swift 2, I won't be able to run the app. But if I do, I get a bunch of errors from the framework. Does anyone have any ideas what I should do for Swift 3 and iOS 10?

Roger Antonell
Roger Antonell
18,252 Points

With Swift 3 you have to download the version 2.0.1 in the Podfile, here you have all the content of the Podfile:

# Uncomment the next line to define a global platform for your project
 platform :ios, '9.0'

target 'VendingMachine' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for VendingMachine
    pod 'Hue', "2.0.1"

end

then the framework isn't throwing more errors, but the content for the function applyBackgroundGradient for swift 3 and hue 2.0.1 is this:

    func applyBackgroundGradient() {
        let lightGray = UIColor.gray
        let darkGrey = UIColor(hex: "#1E2428")
        let gradientLayer = [lightGray, darkGrey].gradient()

        gradientLayer.frame = view.bounds

        gradientLayer.locations = [0.0, 0.5]

        view.layer.insertSublayer(gradientLayer, at: 0)
    }

finally call the function in the viewDidLoad and you have nice gradient as background.

1 Answer

Thanks Roger, that answer was spot on!

I had to update Hue and change the syntax as you demonstrated above.