2012-07-21 55 views
1

我在IOS 5.1模擬器運行下面的代碼時:EXC_BAD_ACCESS設定核心數據對象的標量屬性(IOS 5)

Table* sparkFront = 
    [NSEntityDescription insertNewObjectForEntityForName:@"Table" 
           inManagedObjectContext:_context]; 
NSLog(@"%@", sparkFront); 
NSEntityDescription* entity = [NSEntityDescription entityForName:@"Table" 
              inManagedObjectContext:_context]; 
NSDictionary* dict = [entity propertiesByName]; 
for (NSObject* key in [dict allKeys]) 
{ 
    NSLog(@"%@", key); 
} 
sparkFront.columnValuesAddress = 0x606; 

此代碼與EXC_BAD_ACCESS崩潰上的最後一行。表對象是一個核心數據對象實現如下:

@interface Table : NSManagedObject 
@property (nonatomic) int32_t columnValuesAddress; 
@end 

我知道核心數據本身並不做標量類型,但是這是一個IOS 5+唯一的應用程序,而我的印象是聯合國下屬/拳擊自動完成。在飛機墜毀前,上面的代碼的輸出顯示我的背景和實體都不錯:

2012-07-20 22:17:52.714 otest[95147:7b03] <NSManagedObject: 0x9c87b20> (entity: Table; id: 0x9c86a80 <x-coredata:///Table/t2C0D90D5-E381-4BD0-B65D-8FC83C6D50DB2> ; data: { 
columnValuesAddress = 0; 
}) 
2012-07-20 22:17:52.716 otest[95147:7b03] columnValuesAddress 

空難後,問題報告顯示以下內容:

Application Specific Information: 
objc_msgSend() selector name: isNSNumber__ 
Simulator libSystem was initialized out of order. 


Thread 0 Crashed: 
0 libobjc.A.dylib     0x00635098 objc_msgSend + 12 
1 CoreData      0x05c2e833 _PFManagedObject_coerceValueForKeyWithDescription + 483 
2 CoreData      0x05bfe3d1 _sharedIMPL_setvfk_core + 209 
3 CoreData      0x05c16687 _svfk_0 + 39 
4 ECMCalTests      0x0187f8f1 -[ECMCalTests testInsertRecords] + 849 (ECMCalTests.m:73) 
5 CoreFoundation     0x003f74ed __invoking___ + 29 
6 CoreFoundation     0x003f7407 -[NSInvocation invoke] + 167 
7 SenTestingKit     0x201039c4 -[SenTestCase invokeTest] + 184 
8 SenTestingKit     0x20103868 -[SenTestCase performTest:] + 183 
9 SenTestingKit     0x201034a9 -[SenTest run] + 82 
10 SenTestingKit     0x20106db2 -[SenTestSuite performTest:] + 106 
11 SenTestingKit     0x201034a9 -[SenTest run] + 82 
12 SenTestingKit     0x20106db2 -[SenTestSuite performTest:] + 106 
13 SenTestingKit     0x201034a9 -[SenTest run] + 82 
14 SenTestingKit     0x20105e97 +[SenTestProbe runTests:] + 174 
15 CoreFoundation     0x00492d51 +[NSObject performSelector:withObject:] + 65 
16 otest       0x0000231c 0x1000 + 4892 
17 otest       0x000025be 0x1000 + 5566 
18 otest       0x00002203 0x1000 + 4611 
19 otest       0x00001f8d 0x1000 + 3981 
20 otest       0x00001f31 0x1000 + 3889 

我在做什麼錯?

更新:我根據核心數據教程實現了屬性的setter/getter。它仍然崩潰。它從來沒有在setter中達到一個斷點,所以在它調用setter之前它就會崩潰。我在Apple的代碼中遇到錯誤嗎?

@interface Table : NSManagedObject 
{ 
    int32_t columnValuesAddress; 
} 
@property (nonatomic) int32_t columnValuesAddress; 
@end 

@implementation Table 

- (int32_t)columnValuesAddress 
{ 
    [self willAccessValueForKey:@"columnValuesAddress"]; 
    int32_t address = columnValuesAddress; 
    [self didAccessValueForKey:@"columnValuesAddress"]; 
    return address; 
} 

- (void)setColumnValuesAddress:(int32_t)address 
{ 
    [self willChangeValueForKey:@"columnValuesAddress"]; 
    columnValuesAddress = address; 
    [self didChangeValueForKey:@"columnValuesAddress"]; 
} 

- (void)setNilValueForKey:(NSString *)key 
{ 
    if ([key isEqualToString:@"columnValuesAddress"]) 
    { 
    self.columnValuesAddress = 0; 
    } 
    else 
    { 
    [super setNilValueForKey:key]; 
    } 
} 

@end 
+1

嘗試做拳擊和拆箱自己,看看它是否仍然崩潰 – borrrden 2012-07-21 05:55:20

+0

它說iOS 5自動(聯合國)拳擊? – 2012-07-21 06:13:22

+0

它的確爲你準備的和吸氣劑是我的意思。 – ToBeFrank 2012-07-21 16:01:28

回答

0

我創建了一個全新的項目,從零開始重新創建模型,並將其複製到舊項目的測試代碼中。這個新項目工作正常。我不知道爲什麼舊項目不起作用,但至少有一個解決方案。

+0

這是Xcode中的一個錯誤。我可以確認它在4.4中被修復。 – ToBeFrank 2012-07-28 23:26:47

0

在實體編輯器中,您需要設置您的類。它是在您使用文件模板創建核心數據類文件時爲您設置的。我創建了一個沒有模板的類文件,因此該類沒有設置,所以我得到了這些錯誤。如果它能夠看到課程並且看到您將其指定爲assign,它只會自動打開並取消打開。