English 中文(简体)
页: 1 误差
原标题:NSMutableDictionary error

我想利用安全感来收集一些数据,然后使用。 我的习俗目标如下:

@interface MyData : NSObject {
    NSRange range;
    NSMutableArray *values;
}
@property (nonatomic, retain) NSMutableArray *values;

执行:

- (id)init {
    if (self = [super init]) {
        values = [[NSMutableArray alloc] init];
    }

    return self;
}

以及当一anna大麻ache时,如使用:

NSMutableDictionary *cache = [[NSMutableDictionary alloc] init];
NSString *key = @"KEY";
MyData *data = [[MyData alloc] init];
// save some data into data
[data.values addObject:"DATA1"];
[data.values addObject:"DATA2"];
//... ...
[cache setObject:data forKey:key];

我的问题是切记。 数值为零,但后来又取回该物体如下:

[cache objectForKey:@"KEY"];

i can retrieve "data" and the object s memory address is the same as the address when i put it into cache. what s wrong? i need some kind guys help, any info is helpful. thanks

问题回答

正如Carl Norum所指出的,你通过C strings to addObject:addObject:addObject:,正如其名称所示,需要一个可可物体的点子;Cstring是特性的点子。 您需要通过国家出口管制局的物体;就字面指示而言,这只是要求先将其附在@:>> Fred”是固定的C扼杀,而@“Fred”则是固定的NSString。

http://www.un.org/? 它看不出;它似乎是一个地方变量,这意味着你每次都重新制造新的字典。 因此,你以前(前几位独裁者)在新独裁者中没有任何东西。 这还意味着你再次泄露以前的独裁者,因为你没有释放他们(不是你所显示的法典中的任何一条)。

缩略语 在你的<代码>init方法中设立字典是一种好的方式。 并且确保:: 妥善管理其一生,因此,你不泄露和/或坠毁。

首先,你补充说,在座前不应有“......”。 和@“DATA1”

第二,当你在字典或阵列中添加反对时,它没有实际复制。 如果这些物体被销毁或转移到其他地方,它们也从你的独裁者手中夺走,那么它就会产生一点点。 更妥善地使贵方的价值观成为一刀切的:

MyData* cache = [[MyData alloc] init];

for (int i = 0; i < [data.values count]; i ++){{
    [cache.values addObject:[NSString stringWithString:[data.values objectAtIndex:i]]];
}

在这种情形下使用字典。





相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

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 ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签