在将我的应用程序提交到 Mac App Store 以供审查后,我刚刚收到了一份崩溃报告(在发布时):
Application Specific Information:
objc[1832]: garbage collection is ON
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSDictionary initWithObjects:forKeys:]: count of objects (0) differs from count of keys (2)'
terminate called throwing an exception
abort() called
这是代码的一部分,我怀疑:
- (NSMutableDictionary*)getNewChapterWithTitle:(NSString*)title
{
if (title==nil) title = [NSString stringWithFormat:@"Chapter %d",[[self appChapters] count]+1];
// Align Justify
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setAlignment:NSJustifiedTextAlignment];
// Set Font
NSDictionary *font = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSFont fontWithName:@"Garamond" size:15.0],paragraphStyle, nil] forKeys:[NSArray arrayWithObjects:NSFontAttributeName, NSParagraphStyleAttributeName, nil]];
NSString* lipsum = @"\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc consequat fermentum faucibusPhasellus ac consequat metus. Sed at lectus sit amet tellus vulputate mollis vel suscipit metus. Nulla a sapien purus. Aenean sollicitudin lacus varius nisi faucibus nec lacinia mauris fermentum. Aliquam euismod quam rhoncus ipsum pulvinar quis condimentum magna imperdiet. Nullam augue leo, dictum tincidunt ullamcorper id, porta in lorem. Duis in vestibulum nisl.\
\n\n\
Donec imperdiet dignissim massa, at ultricies enim dignissim at. Etiam pharetra neque quis quam condimentum vitae viverra nisl volutpat. Vivamus urna ante, ultrices ut tincidunt id, auctor id est. Nunc eget diam purus, at viverra orci. Maecenas eu magna mi, id venenatis arcu. Maecenas ornare, tortor sit amet gravida placerat, diam urna lacinia nunc, a dictum arcu libero sed metus. Nulla pulvinar sapien vitae lectus faucibus quis tempus elit volutpat. Integer facilisis interdum lectus, sit amet dapibus enim mattis non. Donec sed pulvinar risus. Mauris in nulla urna, sit amet placerat turpis. Proin felis erat, pretium sed pharetra vel, tincidunt quis tortor. Donec ut nisi dui. Pellentesque gravida gravida justo, quis convallis leo euismod in. Nam pretium accumsan sapien ac interdum.";
NSMutableAttributedString* theLipsum = [[NSMutableAttributedString alloc] initWithString:lipsum attributes:font];
return [[NSMutableDictionary dictionaryWithObjectsAndKeys:
[title retain],@"title",
[theLipsum retain],@"content",
[NSNumber numberWithInt:0],@"isMarkdown",
nil] retain];
}
您是否看到上述任何“明显”错误?(它被调用了 4-5 次,来自awakeFromNib
,所以我想这是罪魁祸首......)
提示: sretain
已添加在报告后;虽然我不知道它是否会有所帮助......