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 trialXavier Avery
8,059 PointsImport 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.
Mirshad Oz
4,545 PointsHey Xavier, Thanks for your message.
True, it doesnt work with video's instruction GameKit library name and works with GameplayKit.
Cheers
jarrod willard
687 PointsHey, 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
Mosses Akizian
8,136 PointsAdding 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
31,289 PointsTry GKRandomSource
Ahmad Ibrahim
Full Stack JavaScript Techdegree Graduate 26,074 PointsThis worked for me...
import GameplayKit
let randomTemperture = GKRandomSource.sharedRandom().nextIntWithUpperBound(150)
Timo Piechotta
3,388 Pointsin 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
4,704 PointsCan 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?
Jeb Holmes
7,717 PointsJeb Holmes
7,717 PointsI 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.