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 Build a Playlist Browser with Swift Building the Music Library and Playlist Models Creating a Data Model

Implicit Dictionaries and alternate explicit declarations not being recognized by Swift challenge requiring one

For some reason, a Swift challenge associated with dictionaries doesn't state it wants only a type annotated initialized dictionary; it doesn't accept an implicit declaration of a dictionary or the use of var caramelDelight: Dictionary.

The challenge accordingly only accepts:

struct ChocolateBox {
  var caramelDelight: [String: String] = ["flavor": "caramel"]
}

If other two ways of successfully completing the challenge are explicitly being ignored/undesired, the error in preview is extremely misleading—particularly the rather surprisingly large error message in the preview plane I've never seen actually propagate inside Xcode.

It seems the challenge prompt needs to be changed accordingly; perhaps Pasan Premaratne can find time to chime in?

ChocolateBox.swift
struct ChocolateBox {
  var caramelDelight: [String: String] = ["flavor": "caramel"]
}

2 Answers

Pasan Premaratne
STAFF
Pasan Premaratne
Treehouse Teacher

Kevin Lozandier

Cool thanks for the update. Your second answer should be valid, odd that it's not working. The first answer however, causes Xcode on my machine to basically explode lol. It is rightly invalid but we'll try returning a much better error message than what you got.

Hey, Pasan:

Understood; it's odd the first answer causes XCode on your machine to explode. On my version of Xcode (6.1.1), it works fine.

Pasan Premaratne
STAFF
Pasan Premaratne
Treehouse Teacher

Kevin Lozandier

Would you mind posting the sample code that generates the error along with the error message?

Hey, Pasan:

The following was attempted instead (both in the code challenge and a Swift Playground to validate they were valid ways of satisfying the challeing:

struct ChocolateBox {
  var caramelDelight: Dictionary = ["flavor": "caramel"]
}

or

struct ChocolateBox {
  var caramelDelight = ["flavor": "caramel"]
}

The error I was provided by the challenge is a long dump:

0  swift                    0x000000010336ca68 llvm::sys::PrintStackTrace(__sFILE*) + 40
1  swift                    0x000000010336cf54 SignalHandler(int) + 452
2  libsystem_platform.dylib 0x00007fff8ce625aa _sigtramp + 26
3  libsystem_platform.dylib 0x00007fe15ad67240 _sigtramp + 3455077552
4  swift                    0x0000000102770bab swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9179
5  swift                    0x00000001026ea110 swift::irgen::IRGenModule::emitGlobalTopLevel() + 208
6  swift                    0x000000010275d8dc performIRGeneration(swift::IRGenOptions&, swift::Module*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1900
7  swift                    0x000000010275e2e3 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 51
8  swift                    0x00000001026b35f4 frontend_main(llvm::ArrayRef, char const*, void*) + 5444
9  swift                    0x00000001026b096d main + 1677
10 libdyld.dylib            0x00007fff946ca5fd start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file swift_lint.swift -target x86_64-apple-darwin13.4.0 -target-cpu core2 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -module-name my_program_lint_build -o /var/folders/4y/79d26rz52wq84ksknz2h86fm0000zn/T/swift_lint-46ca90.o 
1.  While emitting IR SIL function @_TFV21my_program_lint_build12ChocolateBoxCfMS0_FT14caramelDelightVSs10Dictionary_S0_ for 'init' at swift_lint.swift:3:8
:0: error: unable to execute command: Segmentation fault: 11
:0: error: swift frontend command failed due to signal (use -v to see invocation)