iOS SDK how to prevent properties to be saved

Hi,

I am using the iOS SDK and while I love the simplicity of just saving arbitrary objects to the cloud, I would love to have a bit more control. I am used to get objects from cloud as JSON and I use Mantle to generate objects from these JSON data. With Mantle you provide a list for each class with property names that should be “transformed”. Sometimes my model classes have a few dynamically generated properties, like an NSImage that is loaded from the web. But I don’t want this image to be saved in the database.

But I don’t have any chance to specify what should be saved. When I create the schematics in the console, it looks like that with each save/update request the schematics will change once I have added a property.

I really don’t like not to have control. And the API is not open source, I cannot look into the code :-(. I have the issue that the app crashes when using the Backendless API with one of my models. This model has a SCNNode property (SceneKit (3D) Node), NSImage and a few other (rather large and complicated object graphs) properties. But I don’t want them to be saved to the cloud.

As I want more control, I have created my own API using the REST-API. This works fine, however now I am running in a strange error. And before I invest more time to fix that error in my own API I wanted to make sure that I don’t miss something in the “official” API.

Is it possible to have more control over what get’s saved?

Thanks,
Phillip

By the way, this is the exception that is thrown when saving my model with the Backendless iOS API:

Looks like there is a bug when serializing NSColor that are not “named”.

*** -catalogNameComponent not valid for the NSColor NSDeviceRGBColorSpace 1 1 1 1; need to first convert colorspace.

2016-02-25 10:15:20.665 Copper[54654:55889009] (

	0   CoreFoundation                      0x00007fff9157503c __exceptionPreprocess + 172

	1   libobjc.A.dylib                     0x00007fff8a70c76e objc_exception_throw + 43

	2   CoreFoundation                      0x00007fff91574eed +[NSException raise:format:] + 205

	3   AppKit                              0x00007fff90d4ec32 -[NSColor catalogNameComponent] + 76

	4   Foundation                          0x00007fff83a2dd0b -[NSObject(NSKeyValueCoding) valueForKey:] + 385

	5   Foundation                          0x00007fff83ab106d -[NSObject(NSKeyValueCoding) dictionaryWithValuesForKeys:] + 163

	6   Copper                              0x0000000100439eb5 -[ObjectWriter write:format:] + 253

	7   Copper                              0x00000001004395c3 -[ObjectReferenceWriter write:format:] + 320

	8   Copper                              0x0000000100438f02 -[MessageWriter writeObject:format:] + 68

	9   Copper                              0x000000010043acd4 -[V3ObjectSerializer writeObject:fields:format:] + 899

	10  Copper                              0x00000001004395c3 -[ObjectReferenceWriter write:format:] + 320

	11  Copper                              0x0000000100438f02 -[MessageWriter writeObject:format:] + 68

Hi Philip,

With Backendless SDK (objective-C or Swift) the rule of class persistence is:
“all properties (obj-c) or public vars (Swift) of a class object, saved using PersistenceService methods, will be in the Data table with the name of the class”.

So, if you do’nt need that some data of your class is been saved in the table you should declare it as private variable:

  • with obj-c as class extension in .m file, for example:
@interface Contact () {
 NSString *detailInfo;
}
@end 
- with Swift - as 'private' var:
class Contact {
private var detailInfo: String?
} 

The best practice is to divide the data model and other application code in the different classes - in this case the data model class will contain only the properties you need to save in the table.

Regards,
Slava

Ok. Thanks for the info. I will have to separate the classes or use some form of a “transport” class. But what about the issue I posted above. Serializing NSColor crashes in my test application. Don’t you have support for NSColor?

BTW, Backendless SDK is open source: iOS, Android - so, you can investigate the implementation of the all classes.

No, NSColor object cannot be serialize, because it contains many properties of speсific types, for example:

@property (readonly) CGFloat hueComponent;
@property (readonly, strong) NSColorSpace *colorSpace;
@property (readonly, strong) NSImage *patternImage; 

You should implement the data model class with properties of the basic iOS classes (NSString, NSNumber, NSDate). You can also add 1:1 or/and 1:N permissions to another data model (custom) classes. Obviously, the nature iOS classes have a complicated structure, and cannot be saved in the table (or it does not make a sense).

Regards,
Slava