我試圖將封裝到應用中(關於這是什麼代碼是應該做的,看到here的解釋)......這是類「A」的代碼:封裝造成死機
.H文件
@interface ExportBookData : NSObject {
@public NSArray *booksArray;
@public NSMutableDictionary *builtFileList;
@public NSMutableArray *exportData;
}
- (id)initWithCategory: (NSString*) booksellerID;
@end
這是.m文件代碼:
.m文件
@implementation ExportBookData
-(id)initWithCategory: (NSString*) booksellerID {
return (id)booksellerID;
}
@end
這是在「B」級方法(.m文件)的使用該封裝的數據的開頭:
ExportBookData *abe = [[ExportBookData alloc] initWithCategory:@"ABE"];
abe->builtFileList = [NSMutableDictionary dictionary]; <- crash on this line
abe->exportData = [NSMutableArray arrayWithCapacity:abe->booksArray.count];
if(cbvABE.checked) {
我得到上的代碼的第2行以下錯誤指示:
由於我是使用封裝的noob,我沒有看到我做錯了什麼。我跟隨了幾個與我的代碼類似的例子;我做錯了什麼導致這次崩潰?
[NSMutableDictionary dictionary]不分配新的字典。嘗試] [NSMutableDictionary alloc] initWithCapacity:10];例如。 –
這樣做([[NSMutableDictionary alloc] initWithCapacity:10];),同樣的錯誤... – SpokaneDude
哦,對不起,你的init必須先調用超級init,構造函數必須返回self。 –