user1280535
user1280535

Reputation: 347

extracting number from NSDictionary

I am setting the dictionary with NSNmuber- number (for alarm) with :

#define kTimerNameKey @"kTimerNameKey"
 NSDictionary *userInfo = [NSDictionary dictionaryWithObject:number forKey:kTimerNameKey];

When i get on the delegate a notification i have this :

NSDictionary *userInfo = notification.userInfo;

i can log it and see that its ok.

My problem is , how can i extract from userInfo , the number for the key ? if i use objectForKey:kTimerNameKey , he doesnt know this key(its in another class)

So, extracting on the delegate the number from the userInfo is my problem. Thanks.

Upvotes: 0

Views: 270

Answers (3)

Parag Bafna
Parag Bafna

Reputation: 22930

for (NSString* key in userInfo)
{
    int value = [[userInfo objectForKey:key] intValue];
}  

or pass key to another class.

Upvotes: 1

Zhang
Zhang

Reputation: 11607

Can't you just #import "YourOtherClass.h" that contains the definition for the kTimerNameKey ?

Otherwise, if you're using NSNotification to post notification, you can pass along the value of the number:

[[NSNotificationCenter defaultCenter] postNotificationName:@"notif_sendNumber" Object:myNumber];

then in your receiving class, you can go:

-(void)myReceivingMethod:(NSNotification *)notification
{
    NSNumber *receivedNumber = (NSNumber *)[notification object];
}

Upvotes: 0

Try to convert this class to int, like [[userinfo objectForKey:kTimerNameKey] intValue];

Hope it works...

Upvotes: 1

Related Questions