English 中文(简体)
在非 ARC 应用中启动
原标题:NSMutableDictionary initialization in non-ARC app

我不知道我今天是否完全脑筋进化了,或者是什么。但基本上我正试图启动一个NSMMMDD词典,以便使用。我把它作为一个财产:

@property (nonatomic, retain) NSMutableDictionary *baseViewDictionary;

.m 文件 :

@synthesize baseViewDictionary;



// in the init method:
    NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] initWithCapacity:0];
    self.baseViewDictionary = tempDict;
    [self.baseViewDictionary setObject:@"test" forKey:[NSNumber numberWithInteger:0]];
    [tempDict release];

我以为这是一个用于初始化 NSM 运算的图案。 不幸的是, 我的自我. base View 词典从未被设置过 。 我的临时数据仪在调试器里有一对密钥/ 价值配对, 但我的自我。 base View 词典有 0x00000 。 因此它就像 :

self.baseViewDictionary = tempDict;

永远无法运行。 当我步入代码行时, 它跳到@ synthesize size base ViewDictoinary, 然后返回到 self. baseViewDicctionary=tempDict 线 。

s 这里的调试器在 setObject@ "test" 运行后的照片 。

""https://i.sstatic.net/cYLX9.png" alt="此处输入图像描述"/ >

最佳回答

Your pattern is correct.
The initialization is done right, no memory leak as you release the dictionary after the assignation to the property, which retains it.

Are your sure your init method is correct?
I mean, calling self = [ super init ] (not ==), doing your stuff after this, and returning self?

似乎显而易见,但因为您的实例变量似乎是 nil , self 也可能是 nil ...

- ( id )init
{
    if( ( self = [ super init ] ) )
    {
        NSMutableDictionary * tempDict = [ [ NSMutableDictionary alloc ] initWithCapacity: 0 ];
        self.baseViewDictionary        = tempDict;

        [ self.baseViewDictionary setObject: @"test" forKey: [ NSNumber numberWithInteger: 0 ] ];
        [ tempDict release ];

        NSLog( @"%@", self.baseViewDictionary );
    }

    return self;
}
问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签