Objective C指向方法内存错误中指针的指针

时间:2014-03-24 09:41:12

标签: objective-c xcode memory-management

我想从方法中返回2个对象,所以我显然设置了一个通过引用返回NSDictionary和NSIndexPath的方法,它应该不难,但是由于某些原因我在方法完成并返回后得到EXC_BAD_ACCESS错误。

- (NSMutableDictionary *)sortedMessagesUnreadIndexPath:(NSIndexPath **)indexPathForUnreadMessage
{
    ...
    if (indexPathForUnreadMessage != NULL)
        *indexPathForUnreadMessage = [NSIndexPath indexPathForRow:array.count-1 inSection:dict.count-1];
    ...
    return dict;
}

// the call

NSIndexPath *unreadIndexPath = NULL;
self.messages = [self.conversation sortedMessagesUnreadIndexPath:&unreadIndexPath]; 
// EXC_BAD_ACCESS error here AFTER the method return

self.unreadIndexPath = unreadIndexPath;

修改
使用ARC,iOS 7 SDK,Xcode 5

0 个答案:

没有答案