Idrees Ashraf
Idrees Ashraf

Reputation: 1383

static NSMutableDictionary

I want to use static NSMutableDictionary. Can you please help how to use static NSMutableDictionary in class.

Is it right way? .h file

+(NSMutableDictionary*)contactsToAssignBill;
+(void)setContactsToAssignBill:(NSMutableDictionary*)value;

.m file

static NSMutableDictionary * contactsToAssignBill;

+(NSMutableDictionary*)contactsToAssignBill
{
    if (!contactsToAssignBill)
        contactsToAssignBill = [[NSMutableDictionary alloc] init];
    return contactsToAssignBill;
}

+(void)setContactsToAssignBill:(NSMutableDictionary *)value
{
    if(contactsToAssignBill != value)
    {
        [contactsToAssignBill release];
        contactsToAssignBill = [value mutableCopy];
    }
}

Upvotes: 8

Views: 3476

Answers (1)

pzearfoss
pzearfoss

Reputation: 3743

This is the right way to do that. Just bear in mind that the dictionary won't get deallocated at any point.

Upvotes: 2

Related Questions