I'm using an old version of AFNetworking in an app, it works fine except I'm getting on deprecation warning from Xcode from this line in an initWithCoder method:
self.queryStringSerializationStyle = (AFHTTPRequestQueryStringSerializationStyle)[[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(queryStringSerializationStyle))] unsignedIntegerValue];
The specific warning is:
*** -[NSKeyedUnarchiver decodeObjectForKey:]: value for key (queryStringSerializationStyle) is not an object. This will become an error in the future.
From what I can tell with the code (ObjectiveC isn't a big strength of mine) it's because of @selector(queryStringSerializationStyle) which looks to be an attempt to convert the "getter" selector for querySerializationStyle to an NSString. But I don't understand why that's wrong, in fact it works for the line before:
self.mutableHTTPRequestHeaders = [[decoder decodeObjectOfClass:[NSDictionary class] forKey:NSStringFromSelector(@selector(mutableHTTPRequestHeaders))] mutableCopy];
How should I be fixing this?
The problem here isn't related to the selector. It's the serialized value. It's likely that the encoder used
-encodeInteger:forKey:, so the actual thing encoded is an integer, not an NSNumber. When you then decode it as an NSNumber (an object), it's complaining that the types mismatch. Make sure that your encoding and decoding logic match.