Class does not implement methodSignatureForSelector error in Swift

Today I was trying to implement some array manipulation in Swift to find elements with unique property value in an object. Here is the code I was trying to execute.

    let values = NSArray(array: forecastLines!)
    let grps = values.valueForKeyPath("@distinctUnionOfObjects.date_txt")

I was getting hit with following exception.

    2015-12-18 09:48:41.466 WeatherWatch[56504:1522512] *** NSForwarding: warning:
    object 0x7fc191dcc590 of class 'WeatherWatch.OpenWeatherMapData' does not implement
    methodSignatureForSelector: -- trouble ahead
    Unrecognized selector -[WeatherWatch.OpenWeatherMapData valueForKeyPath:]

The exception stumped for a bit. After paying little closer attention to this exception, I noticed mention of methodSigntureForSelector. Well this family of methods are implemented in NSObject class. Then I looked at my OpenWeatherMapData and saw that I did not inherit from NSObject. After the class signature was changed to following, the run time errors disappeared and I was able to get distinct collection of key values.

    public class OpenWeatherMapData:NSObject{...}




14.5 °C / 58.1 °F

weather conditions Clouds

Monthly Posts

Blog Tags