Cast value from NSNotification object

How can I pass an object to NSNotification in integer and string? When I log a notification to the console I get ...

NSConcreteNotification 0x20af70 {name = kMessageCountNotification; object = 1}

But when I set the text value of the UILabel to that value, I get 72855952

+2


a source to share


1 answer


The documentation of the class that sent this notification should contain information about what type of notification it is and what it is sending in its object.

You can access the object posted using the method object

:

ClassOfObjectSent *obj = [notification_you_have_received object];

      

Note that this is a pointer to an object, not a scalar value. If an object NSNumber

, you can get it int

like this:



int i = [obj intValue];

      

If it's a NSString

, you can use it directly, or - safer - create your own copy (if you are using Cocoa Tap or create a non-GC Mac app you will have to release

copy).

NSString *txt = [obj copy];

      

+3


a source







All Articles