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

boris said
boris said
3,607 Points

I am still having an error in the project p-list converter class. Please help.

''' class PlistConverter {

class func dictionaryFromFile(resource: String, ofType Type: String) throws -> [String : 

AnyObject] {

    guard let path = Bundle.main.path(forResource: resource, ofType: Type) else {

        throw InventoryError.InvalidResource
    }
    guard let dictionary = NSDictionary(contentsOfFile: String), let castDictionary = 

dictionary as? [String: Any] else {

      throw InventoryError.ConversionError

    }

    return castDictionary

}

} '''

4 Answers

let castDictionary = dictionary as? [String:AnyObject] instead of [String: Any] because the function returns castDictionary and it must be of type [String: AnyObject]

boris said
boris said
3,607 Points

Hmmmm, I made that correction and I'm still getting the same error

What does the error say?

boris said
boris said
3,607 Points

Cannot convert value of String.Type to expected argument String

(contentsOfFile: path) instead of String

boris said
boris said
3,607 Points

Thanks, you got it working again