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 trialJesse Gay
Full Stack JavaScript Techdegree Student 14,045 PointsWhen I enter default, it disappears, then crashes
I'm trying to add default as the return statement. Default appears in the autocomplete menu, but when I select it, the word disappears. However, if I click on the space after "return", I see an icon (question mark inside a round box). If I option+click on that spot (to try to find more info), Xcode crashes. I've repeated this 3 times.
Tyler Turnbull
10,997 PointsSame problem.. Did you ever figure it out ?
10 Answers
Jesse Gay
Full Stack JavaScript Techdegree Student 14,045 PointsHmmm, I'm taking this course again and now (with Xcode 10.0), default no longer appears in the autocomplete menu. I think I've found a solution. This article says that "Code completion for image literals has been removed in Xcode 10" https://stackoverflow.com/questions/51397347/xcode-10-image-literals-no-longer-available
My solution was to go view>libraries>show media library (or Shift CMD M), then drag and drop the image (named default) into the code after return. It inserts 3 images (maybe because there are 1x, 2x, and 3x versions?) I had to delete 2 of them to make it run. I don't know if that's the best way, but at least it will run without errors now.
Jesse Gay
Full Stack JavaScript Techdegree Student 14,045 PointsYou could also still use
return UIImage(named: "default")!
A more experienced dev told me this is one of the rare cases where forced unwrapping is OK.
Olivier Van hamme
5,418 PointsYes, this is what Pasan showed us before moving on to the more elegant solution, … which does not seem to work with Xcode 10.1. The error message informs me that I can only use default (without the " ") in a switch statement.
Randell Pur
4,934 PointsThat's the only way I could get it to work. Mine was saying default can only work on a switch statement.
James Rimmer
2,603 PointsSo does anyone know then why we don't see the typed word in Xcode 9? i.e. you don't see the word 'default', you just see the image which is barely viewable as it's white. Is this a change between Xcode 8 and Xcode 9?
jbe
8,572 PointsFrom the Xcode 10 release notes:
Code Completion for Swift image literals has been removed in Xcode 10
So the return default
method described in the video tutorial no longer works in Xcode 10 and up.
I am using Xcode 11 and this worked:
return #imageLiteral (resourceName: "default")
Typing the above turns the #imageLiteral (resourceName: "default")
part into a UIImage instance that is unwrapped, and appears as tiny, in-line tiny image (as in the video tutorial.)
This also worked:
return UIImage(imageLiteralResourceName: "default")
This, however does not show an tiny, in-line image; but rather, it stays as a line of code.
Jesse Gay
Full Stack JavaScript Techdegree Student 14,045 PointsTyler Turnbull now I'm getting the same invisible question mark (i.e. it only appears when I mouse over it), but Xcode stopped crashing when I option+click over it. Instead, it just says "No quick help." The app seems to run OK though.
Adam Teale
10,989 PointsSame issue for me - running Xcode 9.4.1. Any luck guys?
Jesse Gay
Full Stack JavaScript Techdegree Student 14,045 PointsIf I comment out the image preview (which, annoyingly, is just a placeholder and gives no info about what it is), I can see the underlying code: return#imageLiteral(resourceName: "Default.png") You can type that in and get the same result, but it will be replaced by the placeholder.
Dan Morse
6,095 PointsJesse, I'm running Xcode 10.1. Typing in the code imageLiteral(resourceName: "Default.png" gave me "Use of unresolved identifier 'imageLiteral'; did you mean'_ImageLiteralType'?
I tried replaced it with this: _ImageLiteralType(imageLiteralResourceName: "default")
No errors so far... so 🤞🏼
Dan Morse
6,095 PointsOk, the code I posted above works. It displays all the right icons and then also will display the default icon if the names don't match up.
Dan Morse
6,095 PointsGrrr, maybe the code I posted above didn't show up. Here it is again: return _ImageLiteralType(imageLiteralResourceName: "default")
Waylan Sands
Courses Plus Student 5,824 PointsBe a big boy and force unwrap it.
return UIImage(named: "default")!
Xavier D
Courses Plus Student 5,840 PointsXavier D
Courses Plus Student 5,840 PointsHi Jesse,
If that happened to me, I would this it's either the app or the OS. I would first trying to delete the app and then re-download from the App Store. If that didn't work, that I would recover my OS by holding down Command R during when I first power on my Mac.
From there, I would follow the prompts, select the appropriate option to install the Mac OS, and after installation, then try to reinstall the Xcode app.
Prior to reinstalling Mac OS, you could try applying First Aid by selecting Disk Utility from the Recovery Menu; however, the I feel the true aid to all Mac issues would be to reinstall the OS. Don't worry about losing your work, your Mac will retain your data and settings.
Good Luck!