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 Swift Collections and Control Flow Control Flow With Conditional Statements The Power of Switching

Xavier Avery
Xavier Avery
8,059 Points

Import GameKit error in Xcode

When I type the import GameKit like in the video, Xcode runs but then says the the execution fails in the debug area and doesn't display a random number on the side like in the video on treehouse. Why is that? Im just trying to make sure my Xcode is running correctly.

Jeb Holmes
Jeb Holmes
7,717 Points

I think there might be some confusion in this video between importing the "GameKit" and GameplayKit" frameworks. According to Apple, the randomization the video uses is part of the "GameplayKit" framework:

https://developer.apple.com/reference/gameplaykit/gkrandomsource

It should work if you use "import GameplayKit" instead.

Hey Xavier, Thanks for your message.

True, it doesnt work with video's instruction GameKit library name and works with GameplayKit.

Cheers

jarrod willard
jarrod willard
687 Points

Hey, I just wanted to say that on a MacBook Air, Import GameKit worked fine. Then on an iMac, with the exact same playground file, Import GameKit gives me an error that starts with:

Playground execution failed: error: Couldn't lookup symbols:

On that computer, if I change it to Import GameplayKit, it works normally again.

Both computers are on macOS v10.12.6 and xCode v8.3.3.

5 Answers

Adding this as an answer so others can see as well since I was confused as to why it wasn't working for me as well.

As Jeb Holmes and Mirshad Oz mentioned in the comments above, you need to import GameplayKit NOT GameKit

Nick Frozz
Nick Frozz
31,289 Points

Try GKRandomSource

Timo Piechotta
Timo Piechotta
3,388 Points

in Xcode 9.4.1 - swift 4.1 - this works:

import GameplayKit let randomTemperture = GKRandomSource.sharedRandom().nextInt(upperBound: 150)

@Treehouse: seems like you are showing code that does not work anymore... not good.

codyl
codyl
4,704 Points

Can anyone explain why someone would need to import Gameplaykit vs. GameKit if they have the same OSX version and same xcode version? Though I don't know why the OSX version would matter anyway?