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 Vending Machine App in Swift 2.0 Loading Data From a Resource Type Casting

Julien Schmitt
Julien Schmitt
2,334 Points

Missing return in a function

Hi,

I'm getting an error but I don't know why. Copied what was done in the course but I'm getting "Missing return in a function expected to return [String: AnyObject] when the return type is specified. Why?

class PlistConverter {
    class func dictionaryFromFile(resource: String, ofType type: String) throws -> [String : AnyObject] {

        guard let path = NSBundle.mainBundle().pathForResource(resource, ofType: type) else {
            throw InventoryError.InvalidResource
        }
        guard let dictionary = NSDictionary(contentsOfFile: path),
        let castDictionary = dictionary as? [String : AnyObject] else {
            throw InventoryError.ConversionError <-- Error here 
        }

        return castDictionary
    }
}

Copied what was done in the course but I'm getting an error "Missing return in a function expected to return [String: AnyObject] when the return type is specified. Why?

Thanks,

Julien

Martin Wildfeuer
Martin Wildfeuer
Courses Plus Student 11,071 Points

Tbh, I cannot see an error in the snippet you posted... Have you tried clearing derived data and the build?

1 Answer

Julien Schmitt
Julien Schmitt
2,334 Points

I just made the build and it disappeared...