I am getting an exception when I filter and try to delete records from Realm DB. It appears that the records are being deleted. The do / catch however is not responding as I expected. What am I doing wrong?
func deleteRecords (module: String, version:String, workorder: String) {
let realm = try! Realm()
let predicate = NSPredicate(format: "module = %# && version = %# && workorder = %#" , module, version, workorder)
let results = realm.objects(NewRecord.self).filter(predicate)
print("FILTERED: \(results.count) \(results)")
do {
try? realm.write {
for result in results {
print("DELETING: \(result)")
realm.delete(result)
}
}
} catch {
// Catch anything that the above catches didn't catch
print("ERROR THROWN DELETONG")
}
}
The output looks like so:
FILTERED: 2 Results<NewRecord> <0x7f9cb1d27950> (
[0] NewRecord {
id = eaAerator008quantityWRK-000001;
module = eaAerator;
workorder = WRK-000001;
version = 008;
field = quantity;
measure = None;
valueString = 200;
valueData = < — 0 total bytes>;
diStatus = INSTALLED;
},
[1] NewRecord {
id = eaAerator008installedQuantityWRK-000001;
module = eaAerator;
workorder = WRK-000001;
version = 008;
field = installedQuantity;
measure = None;
valueString = 150;
valueData = < — 0 total bytes>;
diStatus = INSTALLED;
}
)
DELETING: NewRecord {
id = eaAerator008quantityWRK-000001;
module = eaAerator;
workorder = WRK-000001;
version = 008;
field = quantity;
measure = None;
valueString = 200;
valueData = < — 0 total bytes>;
diStatus = INSTALLED;
}
DELETING: NewRecord {
id = eaAerator008installedQuantityWRK-000001;
module = eaAerator;
workorder = WRK-000001;
version = 008;
field = installedQuantity;
measure = None;
valueString = 150;
valueData = < — 0 total bytes>;
diStatus = INSTALLED;
}
2017-08-13 23:05:07.982 DSMTracker[925:147376108] *** Terminating app due to uncaught exception 'RLMException', reason: 'Object has been deleted or invalidated.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000107bbab0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000106d03141 objc_exception_throw + 48
2 Realm 0x00000001055eccf3 _ZL17RLMVerifyAttachedP13RLMObjectBase + 83
3 Realm 0x00000001055ee94c _ZN12_GLOBAL__N_18getBoxedIN5realm10StringDataEEEP11objc_objectP13RLMObjectBasem + 28
4 Realm 0x00000001055ee927 ___ZN12_GLOBAL__N_115makeBoxedGetterIN5realm10StringDataEEEP11objc_objectm_block_invoke + 39
5 DSMTracker 0x00000001044bdfb9 _TFC10DSMTracker23DirectInstallController9tableViewfTCSo11UITableView6commitOSC27UITableViewCellEditingStyle8forRowAtV10Foundation9IndexPath_T_ + 841
6 DSMTracker 0x00000001044be0af _TToFC10DSMTracker23DirectInstallController9tableViewfTCSo11UITableView6commitOSC27UITableViewCellEditingStyle8forRowAtV10Foundation9IndexPath_T_ + 95
7 UIKit 0x000000010942ec8c -[UITableView _animateDeletionOfRowWithCell:] + 172
8 UIKit 0x0000000109404289 __52-[UITableView _swipeActionButtonsForRowAtIndexPath:]_block_invoke + 84
9 UIKit 0x0000000109430334 -[UITableView _actionButton:pushedInCell:] + 212
10 UIKit 0x0000000109690d75 -[UITableViewCell _actionButtonPushed:] + 82
11 UIKit 0x00000001092c1d22 -[UIApplication sendAction:to:from:forEvent:] + 83
12 UIKit 0x000000010944625c -[UIControl sendAction:to:forEvent:] + 67
13 UIKit 0x0000000109446577 -[UIControl _sendActionsForEvents:withEvent:] + 450
14 UIKit 0x00000001094454b2 -[UIControl touchesEnded:withEvent:] + 618
15 UIKit 0x00000001097eaea9 _UIGestureEnvironmentSortAndSendDelayedTouches + 5553
16 UIKit 0x00000001097e5ec0 _UIGestureEnvironmentUpdate + 1409
17 UIKit 0x00000001097e58f3 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 484
18 UIKit 0x00000001097e4aba -[UIGestureEnvironment _updateGesturesForEvent:window:] + 274
19 UIKit 0x0000000109330b9a -[UIWindow sendEvent:] + 4092
20 UIKit 0x00000001092dd7b0 -[UIApplication sendEvent:] + 352
21 UIKit 0x0000000109ac0adc __dispatchPreprocessedEventFromEventQueue + 2926
22 UIKit 0x0000000109ab8a3a __handleEventQueue + 1122
23 CoreFoundation 0x0000000107b60c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
24 CoreFoundation 0x0000000107b460cf __CFRunLoopDoSources0 + 527
25 CoreFoundation 0x0000000107b455ff __CFRunLoopRun + 911
26 CoreFoundation 0x0000000107b45016 CFRunLoopRunSpecific + 406
27 GraphicsServices 0x0000000110337a24 GSEventRunModal + 62
28 UIKit 0x00000001092c00d4 UIApplicationMain + 159
29 DSMTracker 0x00000001048cad27 main + 55
30 libdyld.dylib 0x000000010ca6d65d start + 1
31 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Related
I have an iOS app that uses Firebase Crashlytics for reporting crashes. Now I have a report for a crash but my problem is that I could not understand what exactly caused the crash from this report.
Crashlytics report:
Crashed: com.apple.main-thread
0 Nail it 0x104db77a8 CaseDetailsViewController.getbaseData() + 253
(CaseDetailsViewController.swift:253)
1 Nail it 0x104db5168 CaseDetailsViewController.viewDidLoad() + 4335047016 (<compiler-generated>:4335047016)
2 Nail it 0x104db521c #objc CaseDetailsViewController.viewDidLoad() + 4335047196 (<compiler-generated>:4335047196)
3 UIKitCore 0x185d11658 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 100
4 UIKitCore 0x185d160e8 -[UIViewController loadViewIfRequired] + 936
5 UIKitCore 0x185d164f0 -[UIViewController view] + 28
6 UIKit 0x1b913374c -[UIViewControllerAccessibility dismissViewControllerWithTransition:completion:] + 268
7 UIKitCore 0x185d28d6c -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 508
8 UIKitCore 0x185d2b474 -[UIViewController dismissViewControllerAnimated:completion:] + 132
9 UIKit 0x1b91333c0 -[UIViewControllerAccessibility dismissViewControllerAnimated:completion:] + 120
10 Nail it 0x104db98ec #objc CaseDetailsViewController.backButton(_:) + 4335065324 (<compiler-generated>:4335065324)
11 UIKitCore 0x18635a72c -[UIApplication sendAction:to:from:forEvent:] + 96
12 UIKitCore 0x185a05474 __45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 80
13 UIKitCore 0x185a05304 -[_UIButtonBarTargetAction _invoke:forEvent:] + 236
14 UIKitCore 0x18635a72c -[UIApplication sendAction:to:from:forEvent:] + 96
15 UIKitCore 0x185d6aed0 -[UIControl sendAction:to:forEvent:] + 240
16 UIKitCore 0x185d6b228 -[UIControl _sendActionsForEvents:withEvent:] + 396
17 UIKitCore 0x185d6a24c -[UIControl touchesEnded:withEvent:] + 516
18 UIKitCore 0x18639449c -[UIWindow _sendTouchesForEvent:] + 1280
19 UIKitCore 0x186395c64 -[UIWindow sendEvent:] + 3468
20 UIKitCore 0x1863718ec -[UIApplication sendEvent:] + 344
21 UIKit 0x1b90db80c -[UIApplicationAccessibility sendEvent:] + 96
22 UIKitCore 0x1863f2970 __dispatchPreprocessedEventFromEventQueue + 6808
23 UIKitCore 0x1863f54ec __handleEventQueueInternal + 5364
24 UIKitCore 0x1863ed168 __handleHIDEventFetcherDrain + 140
25 CoreFoundation 0x182223ad8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
26 CoreFoundation 0x182223a30 __CFRunLoopDoSource0 + 80
27 CoreFoundation 0x1822231b8 __CFRunLoopDoSources0 + 184
28 CoreFoundation 0x18221e1e8 __CFRunLoopRun + 788
29 CoreFoundation 0x18221dba8 CFRunLoopRunSpecific + 424
30 GraphicsServices 0x18c394344 GSEventRunModal + 160
31 UIKitCore 0x1863593e4 UIApplicationMain + 1932
32 Nail it 0x104d797cc main + 16 (AppDelegate.swift:16)
33 libdyld.dylib 0x1820a58f0 start + 4
Below is the function getBaseData() from CasesDetails View Controller:
func getbaseData(){
let userDefaults = UserDefaults.standard
mobile = userDefaults.value(forKey: "mobile") as! String
altenativeMobile = userDefaults.string(forKey: "altenativeMobile") ?? mobile
privateKey = userDefaults.value(forKey: "privateKey") as! String
////reading JSON
let categoriesJsonString = userDefaults.value(forKey: "categoriesString") as! String
let data = categoriesJsonString.data(using: .utf8)!
if let json = try? JSON(data: data) {
let arrayCats = json["content"][1]["caseMappings"][caseCategoryGlobal].array
if(isNoSubsGlob == 0){
if let arrayCatsCount = arrayCats?.count {
print("The array has been created with \(arrayCatsCount) element")
print("sub1Glob= \(sub1Glob) & sub2Glob= \(sub2Glob)")
for var i in 0..<arrayCatsCount{
let sub1 = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["sub1"].string!
let sub2 = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["sub2"].string ?? ""
if (sub1 == sub1Glob && sub2 == sub2Glob){
departmentId = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["departmentId"].int!
WorkTypeId = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["categoryId"].int!
issueCode = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["id"].int!
}
}
}
}else{
departmentId = json["content"][1]["caseMappings"][caseCategoryGlobal][0]["departmentId"].int!
WorkTypeId = json["content"][1]["caseMappings"][caseCategoryGlobal][0]["categoryId"].int!
issueCode = json["content"][1]["caseMappings"][caseCategoryGlobal][0]["id"].int!
}
}
contactNumberText.text = altenativeMobile
}
and the line 235 is (contactNumberText.text = altenativeMobile) as the last line in the code above
All UI stuff should be performed on main thread, that is what your crash report shows (crash due to main thread.)
So your last line should be :
DispatchQueue.main.async {
self.contactNumberText.text = altenativeMobile
}
Update this line, your crash will fixed.
I've created an application in xcode that gets the location of a place from a user longclick on a map and inserte into a database. i keep getting this error
Travel Map Book[17935:3752754] *** Terminating app due to uncaught exception
'NSUnknownKeyException', reason: '[<Locations 0x60800009f630>
valueForUndefinedKey:]: the entity Locations is not key value coding-compliant
for the key "longtitude".'
*** First throw call stack:
(
0 CoreFoundation 0x00000001065d2b0b
__exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000102870141 objc_exception_throw + 48
2 CoreFoundation 0x00000001065d2a59 -[NSException raise] + 9
3 CoreData 0x0000000102de121b -[NSManagedObject valueForUndefinedKey:] + 299
4 Travel Map Book 0x00000001021e04d7 _TFC15Travel_Map_Book19FirstViewController9fetchDatafT_T_ + 7159
5 Travel Map Book 0x00000001021de18a _TFC15Travel_Map_Book19FirstViewController11viewDidLoadfT_T_ + 490
6 Travel Map Book 0x00000001021de202 _TToFC15Travel_Map_Book19FirstViewController11viewDidLoadfT_T_ + 34
7 UIKit 0x00000001036ab01a -[UIViewController loadViewIfRequired] + 1235
8 UIKit 0x00000001036e9e6c -[UINavigationController _layoutViewController:] + 56
9 UIKit 0x00000001036ea74a -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 466
10 UIKit 0x00000001036ea8bb -[UINavigationController _startTransition:fromViewController:toViewController:] + 127
11 UIKit 0x00000001036eba03 -[UINavigationController _startDeferredTransitionIfNeeded:] + 843
12 UIKit 0x00000001036ecb41 -[UINavigationController __viewWillLayoutSubviews] + 58
13 UIKit 0x00000001038de60c -[UILayoutContainerView layoutSubviews] + 231
14 UIKit 0x00000001035cb55b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268
15 QuartzCore 0x000000010b7bd904 -[CALayer layoutSublayers] + 146
16 QuartzCore 0x000000010b7b1526 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 370
17 QuartzCore 0x000000010b7b13a0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
18 QuartzCore 0x000000010b740e92 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
19 QuartzCore 0x000000010b76d130 _ZN2CA11Transaction6commitEv + 468
20 QuartzCore 0x000000010b76db37 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 115
21 CoreFoundation 0x0000000106578717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
22 CoreFoundation 0x0000000106578687 __CFRunLoopDoObservers + 391
23 CoreFoundation 0x000000010655d038 CFRunLoopRunSpecific + 440
24 UIKit 0x000000010350208f -[UIApplication _run] + 468
25 UIKit 0x0000000103508134 UIApplicationMain + 159
26 Travel Map Book 0x00000001021dd177 main + 55
27 libdyld.dylib 0x0000000106f9f65d start + 1
28 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
I have tried cross-checking every spelling and data-type, still no luck with it. this is my fetchdata function
func fetchData(){
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Locations")
request.returnsObjectsAsFaults = false
do {
let results = try context.fetch(request)
if results.count > 0{
self.titleArray.removeAll(keepingCapacity: false)
self.subtitleArray.removeAll(keepingCapacity: false)
self.longtitudeArray.removeAll(keepingCapacity: false)
self.latitudeArray.removeAll(keepingCapacity: false)
for result in results as! [NSManagedObject]{
if let title = result.value(forKey: "title") as? String{
self.titleArray.append(title)
}
if let subtitle = result.value(forKey: "subtitle") as? String{
self.subtitleArray.append(subtitle)
}
if let latitude = result.value(forKey: "latitude") as? Double{
self.latitudeArray.append(latitude)
}
if let longtitude = result.value(forKey: "longitude") as? Double{
self.longtitudeArray.append(longtitude)
}
self.tableView.reloadData()
}
}
} catch {
print("error")
}
}
I am adding Realm source files in my project. I want to create realm class dynamically. Following is my demo code:
-(void)createDynamicClassObject
{
[self createDynamicSchema];
[self createDynamicSchema2];
}
-(void)createDynamicSchema{
_schema = [[RLMSchema alloc] init];
RLMProperty *prop = [[RLMProperty alloc] initWithName:#"a"
type:RLMPropertyTypeInt
objectClassName:nil
linkOriginPropertyName:nil
indexed:NO
optional:NO];
RLMObjectSchema *objectSchema1 = [[RLMObjectSchema alloc] initWithClassName:#"TrulyDynamicObject"
objectClass:RLMObject.class properties:#[prop]];
_schema.objectSchema = #[objectSchema1];
NSLog(#"dyrealm %#",_dyrealm);
NSLog(#"schema %#",[_schema schemaForClassName:#"TrulyDynamicObject"]);
}
-(void)createDynamicSchema2 {
RLMProperty *prop1 = [[RLMProperty alloc] initWithName:#"apple"
type:RLMPropertyTypeString
objectClassName:nil
linkOriginPropertyName:nil
indexed:NO
optional:NO];
RLMProperty *prop2 = [[RLMProperty alloc] initWithName:#"banana"
type:RLMPropertyTypeFloat
objectClassName:nil
linkOriginPropertyName:nil
indexed:NO
optional:NO];
RLMProperty *prop3 = [[RLMProperty alloc] initWithName:#"Mango"
type:RLMPropertyTypeObject
objectClassName:#"TrulyDynamicObject"
linkOriginPropertyName:nil
indexed:NO
optional:NO];
RLMObjectSchema *objectSchema = [[RLMObjectSchema alloc] initWithClassName:#"DynamicTestObject"
objectClass:RLMObject.class properties:#[prop1,prop2,prop3]];
NSMutableArray *array = [NSMutableArray arrayWithArray:_schema.objectSchema];
[array addObject:objectSchema];
_schema.objectSchema = array;
_dyrealm = [self realmWithTestPathAndSchema:_schema];
NSLog(#"DynamicTestObject dyrealm %#",_dyrealm);
NSLog(#"DynamicTestObject schema %#",[_schema schemaForClassName:#"DynamicTestObject"]);
}
while creating schema2, app is crashing.
2016-06-17 15:10:13.491 realmLibraryDemo[1770:82980] schema TrulyDynamicObject {
a {
type = int;
objectClassName = (null);
linkOriginPropertyName = (null);
indexed = NO;
isPrimary = NO;
optional = NO;
}
}
2016-06-17 15:10:13.499 realmLibraryDemo[1770:82980] *** Terminating app due to uncaught exception 'RLMException', reason: 'Schema validation failed due to the following errors:
- 'Object' property 'Mango' must be nullable.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010217ae65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000101bf1deb objc_exception_throw + 48
2 Realm 0x0000000101281c49 _Z18RLMSetErrorOrThrowP7NSErrorPU15__autoreleasingS0_ + 985
3 Realm 0x00000001012606e6 _Z26RLMRealmTranslateExceptionPU15__autoreleasingP7NSError + 598
4 Realm 0x0000000101260dfc +[RLMRealm openSharedRealm:error:] + 268
5 Realm 0x0000000101261e66 +[RLMRealm realmWithConfiguration:error:] + 4022
6 realmLibraryDemo 0x0000000100fa4eb9 -[ViewController realmWithTestPathAndSchema:] + 217
7 realmLibraryDemo 0x0000000100fa4cb8 -[ViewController createDynamicSchema2] + 776
8 realmLibraryDemo 0x0000000100fa46f6 -[ViewController createDynamicClassObject] + 70
9 realmLibraryDemo 0x0000000100fa42d0 -[ViewController viewDidLoad] + 288
10 UIKit 0x00000001026bef98 -[UIViewController loadViewIfRequired] + 1198
11 UIKit 0x00000001026bf2e7 -[UIViewController view] + 27
12 UIKit 0x0000000102595ab0 -[UIWindow addRootViewControllerViewIfPossible] + 61
13 UIKit 0x0000000102596199 -[UIWindow _setHidden:forced:] + 282
14 UIKit 0x00000001025a7c2e -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x0000000102520663 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
16 UIKit 0x0000000102526cc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760
17 UIKit 0x0000000102523e7b -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x0000000104f28754 -[FBSSerialQueue _performNext] + 192
19 FrontBoardServices 0x0000000104f28ac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
20 CoreFoundation 0x00000001020a6a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x000000010209c95c __CFRunLoopDoSources0 + 556
22 CoreFoundation 0x000000010209be13 __CFRunLoopRun + 867
23 CoreFoundation 0x000000010209b828 CFRunLoopRunSpecific + 488
24 UIKit 0x00000001025237cd -[UIApplication _run] + 402
25 UIKit 0x0000000102528610 UIApplicationMain + 171
26 realmLibraryDemo 0x0000000100fa562f main + 111
27 libdyld.dylib 0x00000001048ce92d start + 1
28 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
How to check whether TrulyDynamicObject is created or not as when I executed code using only [self createDynamicSchema]; it is working fine.
Anybody knows how to create multiple schemas with realm object as a reference when class is dynamically created?
From the "Optional Properties" section of Realm's docs (link):
RLMObject subclass properties always can be nil and thus cannot be included in requiredProperties, and RLMArray does not support storing nil.
Translated into RLMProperty wording, it means that properties of type RLMPropertyTypeObject must be optional since the underlying data format can't guarantee that there will always be a link there.
In the beginning of building my realm models I only had an integer in my League class referencing its sport's id. Then, in order to get all associated leagues of a given sport I defined an inverse relationship in its Realm model.
This resulted in an error message stating that dynamic var sport had to be of type Sport, not Int. So I changed it again, and am now trying to initialize a league by passing in a Sport object which it can use for its relationship.
Now I'm getting another error, which I could find nothing about at all. I don't quite understand the error message, nor does the stack trace really help me finding out more.
class Sport: RLMObject {
dynamic var id: Int = 0
dynamic var sortOrder: Int = 0
dynamic var name: String = ""
dynamic var icon: String = ""
var leagues: [League] {
return linkingObjectsOfClass("League", forProperty: "sport") as! [League]
}
override class func primaryKey() -> String {
return "id"
}
init(json: JSON) {
super.init()
id = json["id"].intValue
name = json["name"].stringValue
icon = json["pictogram"].stringValue
sortOrder = json["sortOrder"].intValue
}
}
My class League:
class League: RLMObject {
dynamic var id: Int = 0
dynamic var sport: Sport? = nil
// Other properties
override class func primaryKey() -> String {
return "id"
}
init(json: JSON, sport: Sport) {
super.init()
id = json["id"].intValue
self.sport = sport
// Initializing other properties
}
}
Error message:
2015-03-19 16:01:41.393 MSUapp[7012:142456] Terminating app due to uncaught exception 'Invalid value', reason: 'object must be of type object'
First throw call stack:
(
0 CoreFoundation 0x0075d686 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x0238da97 objc_exception_throw + 44
2 MSUapp 0x000e41e0 _ZL15RLMPreconditionbP8NSStringS0_z + 211
3 MSUapp 0x000e9cb1 _ZN12_GLOBAL__N_123validate_property_valueEP11RLMPropertyP11objc_objectP8NSString + 485
4 MSUapp 0x000e9077 _ZN12_GLOBAL__N_134update_query_with_value_expressionEP9RLMSchemaP15RLMObjectSchemaRN7tightdb5QueryEP8NSStringP11objc_objectP21NSComparisonPredicate + 2691
5 MSUapp 0x000e4a18 _ZN12_GLOBAL__N_127update_query_with_predicateEP11NSPredicateP9RLMSchemaP15RLMObjectSchemaRN7tightdb5QueryE + 1713
6 MSUapp 0x000e42b2 _Z27RLMUpdateQueryWithPredicatePN7tightdb5QueryEP11NSPredicateP9RLMSchemaP15RLMObjectSchema + 169
7 MSUapp 0x000e1e2b RLMGetObjects + 329
8 MSUapp 0x000d7d62 +[RLMObject objectsWithPredicate:] + 117
9 MSUapp 0x000be58e _TFC6MSUapp24AllLeaguesViewController9tableViewfS0_FTCSo11UITableView21numberOfRowsInSectionSi_Si + 430
10 MSUapp 0x000be6fb _TToFC6MSUapp24AllLeaguesViewController9tableViewfS0_FTCSo11UITableView21numberOfRowsInSectionSi_Si + 75
11 UIKit 0x0147f21f -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 2803
12 UIKit 0x014835da -[UITableViewRowData numberOfRows] + 98
13 UIKit 0x012a753c -[UITableView noteNumberOfRowsChanged] + 176
14 UIKit 0x012a6a41 -[UITableView reloadData] + 1837
15 MSUapp 0x000bdb9e _TFC6MSUapp24AllLeaguesViewController24didFinishLoadingJSONDatafS0_FT_T_ + 238
16 MSUapp 0x000bf664 _TTWC6MSUapp24AllLeaguesViewControllerS_16JSONDataReceiverS_FS1_24didFinishLoadingJSONDataUS1___fQPS1_FT_T_ + 36
17 MSUapp 0x0009490d _TFFC6MSUapp14JSONDataSource18loadRemoteJsonDataFS0_FTSSCS_19GETParameterBuilderFCSo6NSDataT__T_U_FTCSo12NSURLRequestGSqCSo17NSHTTPURLResponse_GSqPSs9AnyObject__GSqCSo7NSError__T_ + 2461
18 MSUapp 0x00092d32 _TPA__TFFC6MSUapp14JSONDataSource18loadRemoteJsonDataFS0_FTSSCS_19GETParameterBuilderFCSo6NSDataT__T_U_FTCSo12NSURLRequestGSqCSo17NSHTTPURLResponse_GSqPSs9AnyObject__GSqCSo7NSError__T_ + 162
19 Alamofire 0x004a697a _TFFFC9Alamofire7Request8responseFDS0_FT5queueGSqCSo8NSObject_10serializerFTCSo12NSURLRequestGSqCSo17NSHTTPURLResponse_GSqCSo6NSData__TGSqPSs9AnyObject__GSqCSo7NSError__17completionHandlerFTS2_GSqS3__GSqPS5___GSqS6___T__DS0_U_FT_T_U_FT_T_ + 394
20 Alamofire 0x004a0d17 _TPA__TFFFC9Alamofire7Request8responseFDS0_FT5queueGSqCSo8NSObject_10serializerFTCSo12NSURLRequestGSqCSo17NSHTTPURLResponse_GSqCSo6NSData__TGSqPSs9AnyObject__GSqCSo7NSError__17completionHandlerFTS2_GSqS3__GSqPS5___GSqS6___T__DS0_U_FT_T_U_FT_T_ + 135
21 Alamofire 0x004a4298 _TTRXFo__dT__XFdCb__dT__ + 40
22 libdispatch.dylib 0x02a8b5ea _dispatch_call_block_and_release + 15
23 libdispatch.dylib 0x02aadbef _dispatch_client_callout + 14
24 libdispatch.dylib 0x02a936bb _dispatch_main_queue_callback_4CF + 993
25 CoreFoundation 0x006b685e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
26 CoreFoundation 0x00674680 __CFRunLoopRun + 2256
27 CoreFoundation 0x00673aeb CFRunLoopRunSpecific + 443
28 CoreFoundation 0x0067391b CFRunLoopRunInMode + 123
29 GraphicsServices 0x0526f2c9 GSEventRunModal + 192
30 GraphicsServices 0x0526f106 GSEventRun + 104
31 UIKit 0x01192366 UIApplicationMain + 1526
32 MSUapp 0x000aba94 main + 180
33 libdyld.dylib 0x02ad8ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
What am I missing? Instead of passing in a sport as an object I also tried to do the following to set the sport:
sport = Sport.objectsWhere("id = %i", json["sport"].intValue).firstObject() as Sport
But that yielded exactly the same exception.
The solution was completely unrelated to this line.
Inside the TableViewController, where Sport is the section and Leagues are its cells, I had the following code to get a league, based on a sport:
var league = League.objectsWhere("sport = %i", sportsList[indexPath.section].id) as League
// sportsList is of type [Sport]
I didn't think about having to change this line too, but once it's a relationship, I had to change it to the following:
var league = League.objectsWhere("sport = %#", sportsList[indexPath.section]) as League
This inserts the whole object, and not just it's id. I guess I'm just too used to using MySQL in web development.
I'm trying to get some rows from DynamoDB in a Swift application. At the very last line in my code below I get a NSInvalidArgumentException. I think it must be because my request is not formatted correctly, but I don't know what is wrong. In the docs (batch operation sample) for the java sdk they use TableKeysAndAttributes, which doesn't seem to exist in the iOS SDK.
Here is my code:
var venueIdAttribute = AWSDynamoDBAttributeValue()
venueIdAttribute.N = "2164156"
var venueIdCondition = AWSDynamoDBCondition()
venueIdCondition.comparisonOperator = .EQ // Hash Key must always be Equals
venueIdCondition.attributeValueList = [venueIdAttribute]
var startDateAttribute = AWSDynamoDBAttributeValue()
var startString = String(format:"%1.0f", lastSyncDate.timeIntervalSince1970 * 1000)
startDateAttribute.N = String(format:"%1.0f", lastSyncDate.timeIntervalSince1970 * 1000)
var dateCondition = AWSDynamoDBCondition()
dateCondition.comparisonOperator = .GT
dateCondition.attributeValueList = [startDateAttribute];
var keysArray : NSArray = [["venueId" : venueIdCondition, "dateInterval" : dateCondition]]
var tableDict : NSDictionary = ["Keys":keysArray]
var requestMap : NSDictionary = ["myTable":tableDict]
var request : AWSDynamoDBBatchGetItemInput = AWSDynamoDBBatchGetItemInput()
request.requestItems = requestMap
request.returnConsumedCapacity = AWSDynamoDBReturnConsumedCapacity.Total
var response : BFTask = dynamoDB.batchGetItem(request) // This is synchronous
Here is the error:
2014-12-18 13:23:17.002 TouchDashboard[8066:503166] +[NSDictionaryI JSONKeyPathsByPropertyKey]: unrecognized selector sent to class 0x10a9930e8
2014-12-18 13:23:17.010 TouchDashboard[8066:503166] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[__NSDictionaryI JSONKeyPathsByPropertyKey]: unrecognized selector sent to class 0x10a9930e8'
*** First throw call stack:
(
0 CoreFoundation 0x000000010a6ebf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010c5b1bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010a6f2f4d +[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010a64b27c ___forwarding_ + 988
4 CoreFoundation 0x000000010a64ae18 _CF_forwarding_prep_0 + 120
5 TouchDashboard 0x0000000109b1176a -[MTLJSONAdapter initWithModel:] + 490
6 TouchDashboard 0x0000000109b0fc47 +[MTLJSONAdapter JSONDictionaryFromModel:] + 87
7 TouchDashboard 0x00000001099a47c5 +[AZModelUtility JSONDictionaryFromMapMTLDictionary:] + 517
8 TouchDashboard 0x0000000109a91c5b 59+[AWSDynamoDBBatchGetItemInput requestItemsJSONTransformer]_block_invoke_2 + 75
9 TouchDashboard 0x0000000109b21718 -[MTLReversibleValueTransformer reverseTransformedValue:] + 88
10 TouchDashboard 0x0000000109b11b90 __32-[MTLJSONAdapter JSONDictionary]_block_invoke + 480
11 CoreFoundation 0x000000010a62d766 __65-[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 102
12 CoreFoundation 0x000000010a62d66c -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 204
13 TouchDashboard 0x0000000109b1192c -[MTLJSONAdapter JSONDictionary] + 300
14 TouchDashboard 0x0000000109b0fc5b +[MTLJSONAdapter JSONDictionaryFromModel:] + 107
15 TouchDashboard 0x00000001099a6829 -[AWSDynamoDB invokeRequest:HTTPMethod:URLString:targetPrefix:operationName:outputClass:] + 313
16 TouchDashboard 0x00000001099a6bd9 -[AWSDynamoDB batchGetItem:] + 153
17 TouchDashboard 0x000000010991a0d7 _TFC14TouchDashboard14ViewController9batchSyncfS0_FT_T_ + 10663
18 TouchDashboard 0x0000000109917349 _TFC14TouchDashboard14ViewController11viewDidLoadfS0_FT_T_ + 1161
19 TouchDashboard 0x0000000109917462 _TToFC14TouchDashboard14ViewController11viewDidLoadfS0_FT_T_ + 34
20 UIKit 0x000000010b41ea90 -[UIViewController loadViewIfRequired] + 738
21 UIKit 0x000000010b41ec8e -[UIViewController view] + 27
22 UIKit 0x000000010b33dca9 -[UIWindow addRootViewControllerViewIfPossible] + 58
23 UIKit 0x000000010b33e041 -[UIWindow _setHidden:forced:] + 247
24 UIKit 0x000000010b34a72c -[UIWindow makeKeyAndVisible] + 42
25 UIKit 0x000000010b2f5061 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
26 UIKit 0x000000010b2f7d2c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
27 UIKit 0x000000010b2f6bf2 -[UIApplication workspaceDidEndTransaction:] + 179
28 FrontBoardServices 0x000000010ebe92a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
29 CoreFoundation 0x000000010a62153c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12
30 CoreFoundation 0x000000010a617285 __CFRunLoopDoBlocks + 341
31 CoreFoundation 0x000000010a616a43 __CFRunLoopRun + 851
32 CoreFoundation 0x000000010a616486 CFRunLoopRunSpecific + 470
33 UIKit 0x000000010b2f6669 -[UIApplication _run] + 413
34 UIKit 0x000000010b2f9420 UIApplicationMain + 1282
35 TouchDashboard 0x000000010992ba2e top_level_code + 78
36 TouchDashboard 0x000000010992ba6a main + 42
37 libdyld.dylib 0x000000010cd8b145 start + 1
38 ??? 0x0000000000000001 0x0 + 1
AWSDynamoDBBatchGetItemInput's requestItems property needs to be a dictionary of the following key/value pair:
NSString (a table name) : AWSDynamoDBKeysAndAttributes (KeysAndAttributes)
Currently, you are passing an instance of NSDictionary as a value. Once you update your code snippet to use AWSDynamoDBKeysAndAttributes, it should work.