I'm looping through an array of objects then getting a value of key "resort" and storing that in another array if it doesn't already exist.
My NSLog result shows that the string is there. However I get the error mentioned in the title of this question. When I replace the string "resortName" with "location" and store the whole object instead the error goes away.
The problem is I need to check for the string as it is the only way I can stop duplicate objects from being stored on this occasion.
objects is an NSArray of parse PFObjects
Here is my code:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
for location in objects {
var resortName = location.valueForKey("resort") as NSString
NSLog("resortname: \(resortName)")
if !_sections.containsObject(resortName) {
_sections.addObject(resortName)
}
}
NSLog("sections: \(_sections.count)")
return _sections.count
}
Any idea what I am doing wrong?
Thanks for your time.
Complete stack:
2014-09-11 16:42:08.635 CharityApp[33639:380242] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0x7fa325842340> valueForUndefinedKey:]: this class is not key value coding-compliant for the key resort.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010f8293f5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001113febb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010f829039 -[NSException raise] + 9
3 Foundation 0x000000010fcd0fba -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 226
4 Foundation 0x000000010fc29543 -[NSObject(NSKeyValueCoding) valueForKey:] + 251
5 CharityApp 0x000000010df14ed0 _TFC8CharityApp31ActivityListTableViewController9tableViewfS0_FTCSo11UITableView23titleForHeaderInSectionSi_GSqSS_ + 976
6 CharityApp 0x000000010df150ac _TToFC8CharityApp31ActivityListTableViewController9tableViewfS0_FTCSo11UITableView23titleForHeaderInSectionSi_GSqSS_ + 92
7 UIKit 0x000000011024c8e1 -[UITableView _delegateWantsHeaderTitleForSection:] + 56
8 UIKit 0x000000011024c8a5 -[UITableView _delegateWantsHeaderForSection:] + 572
9 UIKit 0x00000001103cf81e -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 162
10 UIKit 0x00000001103d55ec -[UITableViewRowData rectForSection:] + 302
11 UIKit 0x00000001103d6583 -[UITableViewRowData indexPathsForRowsInRect:] + 90
12 UIKit 0x000000011023f0ed -[UITableView indexPathsForVisibleRows] + 269
13 CharityApp 0x000000010df5f39a -[PFQueryTableViewController loadImagesForOnscreenRows] + 137
14 UIKit 0x00000001101efb4f -[UIScrollView(UIScrollViewInternal) _stopScrollDecelerationNotify:] + 277
15 UIKit 0x00000001101efd69 -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 479
16 UIKit 0x00000001101ea53a -[UIScrollView _smoothScrollWithUpdateTime:] + 2896
17 QuartzCore 0x000000010e54a8f7 _ZN2CA7Display15DisplayLinkItem8dispatchEv + 37
18 QuartzCore 0x000000010e54a7bf _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 315
19 CoreFoundation 0x000000010f7914e4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
20 CoreFoundation 0x000000010f7910a5 __CFRunLoopDoTimer + 1045
21 CoreFoundation 0x000000010f7543dd __CFRunLoopRun + 1901
22 CoreFoundation 0x000000010f753a06 CFRunLoopRunSpecific + 470
23 GraphicsServices 0x0000000111bc19f0 GSEventRunModal + 161
24 UIKit 0x000000011015a550 UIApplicationMain + 1282
25 CharityApp 0x000000010dedd7ae top_level_code + 78
26 CharityApp 0x000000010dedd8ca main + 42
27 libdyld.dylib 0x00000001122ca145 start + 1
28 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)