objective c - How to NSLog the name of an object in NSArray -
i new objective-c, , reading objective-c: big nerd ranch guide programming. trying add together code completed illustration in hopes of learning how print name of objects in array along values. able print values, stuck on trying print name of objects. help appreciated!
#import <foundation/foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { // create 3 nsdate objects nsdate *now = [nsdate date]; nsdate *tomorrow = [now datebyaddingtimeinterval:24.0 * 60.0 * 60.0]; nsdate *yesterday = [now datebyaddingtimeinterval:-24.0 * 60.0 * 60.0]; // create empty mutable array nsmutablearray *datelist = [[nsmutablearray alloc] init]; // add together 2 dates array [datelist addobject:now]; [datelist addobject:tomorrow]; // add together yesterday @ origin of list [datelist insertobject:yesterday atindex:0]; // iterate on array (nsdate *d in datelist) { nslog(@"here date: %@\n\n", d); sleep(2); } // remove yesterday [datelist removeobjectatindex:0]; nslog(@"now first date is: %@\n\n", datelist[0]); } homecoming 0; }
sounds want utilize nsmutabledictionary instead of nsmutablearray give ability add together object , key each object. 1 time have dictionary can print key , value loop
(nsstring *key in dict) { nslog(@"'%@' = '%@'", key, [dict objectforkey:key]); }
objective-c
No comments:
Post a Comment