User Service: exception is thrown when trying to save user to the persistent store (iOS)

In my app User Service keeps user logged in, so on login it attempts to save current user to the persistent store, and this is when I get the following exception:

‘NSUnknownKeyException’, reason: ‘[<UIImage 0x7d194ff0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key ap_imageHasMonochromeEffect.’

Apparently, it is somehow connected to the fact that user has a field which contains a url of an image and there is a category of UIImage in my project, which declares a field ap_imageHasMonochromeEffect. But I have no clue about a possible solution to this problem.

This is the stack trace:
*** First throw call stack:
(
0 CoreFoundation 0x03f76494 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02eb7e02 objc_exception_throw + 50
2 CoreFoundation 0x03f760b1 -[NSException raise] + 17
3 Foundation 0x02b496d4 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 282
4 Foundation 0x02a8adcc _NSGetUsingKeyValueGetter + 105
5 Foundation 0x02a8ad5b -[NSObject(NSKeyValueCoding) valueForKey:] + 288
6 Foundation 0x02b49922 -[NSObject(NSKeyValueCoding) dictionaryWithValuesForKeys:] + 189
7 MyApp 0x008d758c +[Types propertyDictionary:] + 75
8 MyApp 0x008e136e -[ObjectWriter write:format:] + 508
9 MyApp 0x008e083a -[ObjectReferenceWriter write:format:] + 361
10 MyApp 0x008e00f5 -[MessageWriter writeObject:format:] + 62
11 MyApp 0x008e25e3 -[V3ObjectSerializer writeObject:fields:format:] + 1019
12 MyApp 0x008df320 -[BoundPropertyBagWriter write:format:] + 126
13 MyApp 0x008e083a -[ObjectReferenceWriter write:format:] + 361
14 MyApp 0x008e00f5 -[MessageWriter writeObject:format:] + 62
15 MyApp 0x008d8664 +[AMFSerializer serializeToBytes:type:] + 142
16 MyApp 0x008d85d1 +[AMFSerializer serializeToBytes:] + 34
17 MyApp 0x008d8878 +[AMFSerializer serializeToFile:fileName:] + 103
18 MyApp 0x003deee6 -[UserService setPersistentUser] + 83
19 MyApp 0x003e9e43 -[PersistenceService onCurrentUserUpdate:] + 413
20 MyApp 0x003e9bd6 -[PersistenceService createResponse:] + 204
21 libobjc.A.dylib 0x02ecc059 -[NSObject performSelector:withObject:] + 70
22 MyApp 0x008e46eb -[Responder responseHandler:] + 147
23 MyApp 0x008b879c -[HttpEngine processAsyncAMFResponse:] + 1852
24 MyApp 0x008b9be8 __41-[HttpEngine connectionDidFinishLoading:]_block_invoke + 35
25 libdispatch.dylib 0x0762f363 _dispatch_call_block_and_release + 15
26 libdispatch.dylib 0x076529cd _dispatch_client_callout + 14
27 libdispatch.dylib 0x07637f7c _dispatch_main_queue_callback_4CF + 910
28 CoreFoundation 0x03ec01be CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 14
29 CoreFoundation 0x03e7e434 __CFRunLoopRun + 2356
30 CoreFoundation 0x03e7d846 CFRunLoopRunSpecific + 470
31 CoreFoundation 0x03e7d65b CFRunLoopRunInMode + 123
32 GraphicsServices 0x083e5664 GSEventRunModal + 192
33 GraphicsServices 0x083e54a1 GSEventRun + 104
34 UIKit 0x054a3eb9 UIApplicationMain + 160
35 MyApp 0x0003619a main + 138
36 libdyld.dylib 0x0767ca25 start + 1
)

A symbol “_” is not allowed for user property name, please rename your ap_imageHasMonochromeEffect property, for example - apImageHasMonochromeEffect.

Keep in the mind that you may not save UIImage object as user property

Hi Vyacheslav,

Thank you for the prompt reply!
I changed the property name as you have proposed, but I still get the same exception.

The reason why it didn’t actually help is that ap_imageHasMonochromeEffect is a property of UIImage which is defined in a category and it has nothing to do with user.

What I have mentioned about user is that user has a url of an image, and maybe this info will help in understanding what is going on

Please provide the sample of your code - how do you set your user properties (and them types).

I have an extension of BackendlessUser class and all the computed fields are of types String and Int.
This is how I set properties:

extension BackendlessUser {
//...
var avatarURL: String? {
        get {
            return getProperty("avatarURL") as? String
        }
        set {
            setProperty("avatarURL", object: newValue)
        }

    }
}

This is a bad idea to make extension of BackendlessUser class (it has a special status in Backendless SDK), so you should use simply setProperty and getProperty.

Thank you for the hint!

I have found out that there actually was a computed field of type UIImage in my extension for BackendlessUser class. Now that I have removed it, everything works fine.