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

What is the default value for AnyObject?

Hi everyone! I have a trouble in Swift. I have created a new class in this way:

class geoLocations: RLMObject {
        dynamic var latitude = 0.0
        dynamic var longitude = 0.0
        dynamic var timestamp = NSDate(timeIntervalSince1970: 1)
        dynamic var uuid = ""
        dynamic var fullAddress = ""
        dynamic var countryTwo = ""
        dynamic var realCity = ""
        dynamic var zip = ""
        dynamic var houseNumber = ""
        dynamic var country = ""
        dynamic var street = ""
        dynamic var area = ""
    }

Than I am going to write:

let Location = geoLocations()
Location.latitude = placemark.location.coordinate.latitude
Location.area = placemark.addressDictionary.values.array[8]

And Xcode says that AnyObject isn't convertible to String. I have tried to do "init" but than Xcode asks me to describe all in geoLocations(). But it doesn't work.

RLMObject is an object from realm library (realm.io)

What can I write as a default value for AnyObject? Than everything will work.

3 Answers

setting it to nil will probably work.

Unfortunately, not:(

Anybody?)

Hi Artem can you share more what you are trying to do? The default values you are setting for each property should work. Where is the error happening? Most AnyObject isn't convertible to String happen when you don't cast a value as String.

I'm guessing you are seeing this here: Location.area = placemark.addressDictionary.values.array[8] add as String to the end of this to let Xcode know that you know it will return a string