Hi all, newbie here. This is a rather simple question as the title suggests may I know how to do it? because currently I’m having a problem to save the array into couchbase lite.
sample self.orders data
[{
"taxPercent" : 7,
"state" : "opened",
"netSubtotalAdj" : 0,
"serviceChargePercent" : 10,
"humanReadableCreatedTime" : "10:47",
"uuid" : "161121DEV9500001",
"table" : {
"priority" : 5,
"syncStatus" : "local.update",
"name" : "T4",
"coordinate" : {
},
"state" : "occupied",
"tableId" : 278,
"orderUUID" : "161121DEV9500001"
},
"payments" : [
],
"allOrderItems" : [
],
"subtotal" : 0,
"allActiveItems" : [
],
"syncStatus" : "local.create",
"updatedAt" : "2016-11-21T02:47:19.986Z",
"adjustments" : [
],
"offlineOrderItems" : [
],
"orderType" : "eat-in",
"createdAt" : "2016-11-21T02:47:19.995Z",
"unsentOrderItems" : [
],
"pax" : 1,
"orderItems" : [
],
"staff" : {
"isManager" : 1,
"name" : "Victor Heng",
"is_manager" : true,
"webToken" : "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOjEsImV4cCI6MTQ3OTc4MjgzNDM5NSwicG9zR3VpZCI6ImRldm1hc3RlciJ9.BflWDH4EHNckhaEkL_ytYfXs5QlmOCGPSsZVANZZDPU",
"permissions" : [
{
"permissionDescription" : "Store Administration",
"type" : "manager",
"uuid" : "store_admin"
}
],
"staffId" : 1,
"pin" : "1234"
},
"humanReadableCreatedDateTime" : "21-11-2016 10:47"
}]
when i try to insert the self.orders to newRev[@“orders”]
// self.orders is a mutableArray
if(self.orders) {
if (![doc update: ^BOOL(CBLUnsavedRevision *newRev) {
newRev[@"orders"] = self.orders;
return YES;
} error: &error]) {
NSLog(@"Error : cannot update Orders");
}
}
i got this error
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SSSOrder cbjson_encodeTo:canonical:]: unrecognized selector sent to instance 0x7a14d960'
*** First throw call stack:
(
0 CoreFoundation 0x02c39a94 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02368e02 objc_exception_throw + 50
2 CoreFoundation 0x02c42de3 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x02b80e3d ___forwarding___ + 1037
4 CoreFoundation 0x02b80a0e _CF_forwarding_prep_0 + 14
5 Sphere 0x004c9727 -[NSArray(CBJSONEncoder) cbjson_encodeTo:canonical:] + 209
6 Sphere 0x004c9c61 -[NSDictionary(CBJSONEncoder) cbjson_encodeTo:canonical:keyFilter:error:] + 548
7 Sphere 0x004c8fde -[CBJSONEncoder encode:] + 135
8 Sphere 0x00442cb4 +[CBL_Revision asCanonicalJSON:error:] + 162
9 Sphere 0x00504619 -[CBL_SQLiteStorage addDocID:prevRevID:properties:deleting:allowConflict:validationBlock:status:error:] + 187
10 Sphere 0x004c23ea -[CBLDatabase(Insertion) putDocID:properties:prevRevisionID:allowConflict:source:status:error:] + 1245
11 Sphere 0x0048156a -[CBLDocument putProperties:prevRevID:allowConflict:error:] + 188
12 Sphere 0x00486288 -[CBLUnsavedRevision save:] + 129
13 Sphere 0x004816fb -[CBLDocument update:error:] + 139
14 Sphere 0x0030483a -[SSSSphereHost save] + 458
15 Sphere 0x00273786 -[SSSSphereHost(SSSOrderService) createOrder:completionHandler:] + 1814
16 Sphere 0x00103584 -[SSSOrderViewModel createOrderOnComplete:] + 308
17 Sphere 0x00172243 __45-[SSSSalesViewController createNewTableOrder]_block_invoke + 915
18 Sphere 0x002f3ea2 -[SSSKeypadInputViewController doneButtonPressed:] + 162
19 libobjc.A.dylib 0x0237d0b5 -[NSObject performSelector:withObject:withObject:] + 84
20 UIKit 0x040d1c40 -[UIApplication sendAction:to:from:forEvent:] + 118
21 UIKit 0x040d1bbf -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
22 UIKit 0x042678fc -[UIControl sendAction:to:forEvent:] + 79
23 UIKit 0x04267c7c -[UIControl _sendActionsForEvents:withEvent:] + 408
24 UIKit 0x04266c87 -[UIControl touchesEnded:withEvent:] + 714
25 UIKit 0x04148eb8 -[UIWindow _sendTouchesForEvent:] + 1095
26 UIKit 0x04149da4 -[UIWindow sendEvent:] + 1118
27 UIKit 0x040f29b3 -[UIApplication sendEvent:] + 266
28 UIKit 0x040c9903 _UIApplicationHandleEventQueue + 7327
29 CoreFoundation 0x02b53e7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
30 CoreFoundation 0x02b49b0b __CFRunLoopDoSources0 + 523
31 CoreFoundation 0x02b48f28 __CFRunLoopRun + 1032
32 CoreFoundation 0x02b48866 CFRunLoopRunSpecific + 470
33 CoreFoundation 0x02b4867b CFRunLoopRunInMode + 123
34 GraphicsServices 0x06dfa664 GSEventRunModal + 192
35 GraphicsServices 0x06dfa4a1 GSEventRun + 104
36 UIKit 0x040cfcc1 UIApplicationMain + 160
37 Sphere 0x0026c13c main + 140
38 libdyld.dylib 0x05607a21 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I expect the document to look something like this
{
"_id" = document;
"_rev" = "36-5413c0f8f07e003b8aaf69ba36baab3f";
orders = {
[order1],
[order2],
[order3]
};
and to retrieve the list of orders this way
CBLDocument* doc = [SSSAppDelegate.documentDatabase documentWithID: @"document"];
doc.properties[@"orders"][0] // order1
it works fine when you insert a dictionary to a field but what I want is to insert a list of dictionaries to a field.
your help is appreciated thanks!