我在尝试从我的领域读取数据到tableView时遇到了问题。
我的模型看起来像这样:
class DiaryEntry: RLMObject {
dynamic var date = NSDate()
dynamic var word = ""
dynamic var text = ""
dynamic var imagePath = ""
dynamic var mood: Int = 6
}
从realm.io检索我跟随tableView-Example的条目 一旦我尝试访问任何字符串属性,应用程序崩溃,而原始示例按预期工作。
let entry = array[0] as DiaryEntry
println(entry.description)
header.lblDate?.text = entry.date.description
header.lblHeadline?.text = entry.word // App crashes here
日志输出:
DiaryEntry {
date = 2015-01-22 16:08:41 +0000;
word = blabla;
text = asdfads;
imagePath = ;
mood = 6;
}
table.cpp:2431: [realm-core-0.88.0] Assertion failed: type == col_type_StringEnum
0 trust 0x000000010e55e956 _ZN7tightdb4util9terminateEPKcS2_l + 454
1 trust 0x000000010e679896 _ZNK7tightdb5Table10get_stringEmm + 518
2 trust 0x000000010e4c6174 _ZNK7tightdb8RowFuncsINS_5TableENS_8BasicRowIS1_EEE10get_stringEm + 84
3 trust 0x000000010e4c10fb _ZL12RLMGetStringP13RLMObjectBasem + 59
4 trust 0x000000010e4c550f ___ZL17RLMAccessorGetterP11RLMPropertycP8NSString_block_invoke_8 + 47
5 trust 0x000000010e456860 _TFC5trust19DiaryViewController9tableViewfS0_FTCSo11UITableView22viewForHeaderInSectionSi_GSqCSo6UIView_ + 2384
6 trust 0x000000010e4570f2 _TToFC5trust19DiaryViewController9tableViewfS0_FTCSo11UITableView22viewForHeaderInSectionSi_GSqCSo6UIView_ + 66
7 trust 0x000000010e549bdb -[STCollapseTableView tableView:viewForHeaderInSection:] + 155
8 UIKit 0x000000010f1e2d5e -[UITableView _delegateViewForHeaderInSection:] + 45
9 UIKit 0x000000010f1e63b4 __96-[UITableView _sectionHeaderView:withFrame:forSection:floating:reuseViewIfPossible:willDisplay:]_block_invoke + 97
10 UIKit 0x000000010f1615ce +[UIView(Animation) performWithoutAnimation:] + 65
11 UIKit 0x000000010f1e6261 -[UITableView _sectionHeaderView:withFrame:forSection:floating:reuseViewIfPossible:willDisplay:] + 531
12 UIKit 0x000000010f1e6b50 -[UITableView _sectionHeaderViewWithFrame:forSection:floating:reuseViewIfPossible:willDisplay:] + 85
13 UIKit 0x000000010f1c5c66 -[UITableView _updateVisibleHeadersAndFootersNow:] + 2582
14 UIKit 0x000000010f1c7354 -[UITableView _updateVisibleCellsNow:isRecursive:] + 3777
15 UIKit 0x000000010f1dce3c -[UITableView layoutSubviews] + 213
16 UIKit 0x000000010f169973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
17 QuartzCore 0x000000010ef7bde8 -[CALayer layoutSublayers] + 150
18 QuartzCore 0x000000010ef70a0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
19 QuartzCore 0x000000010ef7087e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
20 QuartzCore 0x000000010eede63e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
21 QuartzCore 0x000000010eedf74a _ZN2CA11Transaction6commitEv + 390
22 QuartzCore 0x000000010ef9e6bd _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 489
23 CoreFoundation 0x0000000110499f64 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
24 CoreFoundation 0x0000000110499b25 __CFRunLoopDoTimer + 1045
25 CoreFoundation 0x000000011045ce5d __CFRunLoopRun + 1901
26 CoreFoundation 0x000000011045c486 CFRunLoopRunSpecific + 470
27 GraphicsServices 0x0000000112a939f0 GSEventRunModal + 161
28 UIKit 0x000000010f0f0420 UIApplicationMain + 1282
29 trust 0x000000010e4b99ee top_level_code + 78
30 trust 0x000000010e4b9a2a main + 42
31 libdyld.dylib 0x0000000111366145 start + 1
32 ??? 0x0000000000000001 0x0 + 1
IMPORTANT: if you see this error, please send this log to help@realm.io.
正如您所看到的,对象描述看起来非常好,但访问属性并未按预期工作。
我测试了0.89以及0.90。
编辑:我找到了解决方法!当我在DiaryEntry.allObjects()
中执行简单application(_:didFinishLaunchingWithOptions:)
时,它按预期工作o0