Home Tutorial Iphone Examples Nslog NSLog NSDictionary Example code


Share on Google+Share on Google+
NSLog NSDictionary Example code
Posted on: July 29, 2009 at 12:00 AM
In this example code we will learn how to print the value of NSDictionary

The following code example prints the data of NSDictionary.

You can use the NSLog function to debug your program. In this example we will be showing you the code that prints the value of NSDictionary object.

//  HelloDictionary.h
//  DataTypes

#import <Foundation/Foundation.h>

@interface HelloDictionary : NSObject {

    NSDictionary *dictionary;


-(void) print;


The implementation class is as follows:

//  HelloDictionary.m
//  DataTypes

#import "HelloDictionary.h"

@implementation HelloDictionary

-(void) print


    NSArray *keys = [NSArray arrayWithObjects:@"key1", @"key2", @"key3", nil];

    NSArray *objects = [NSArray arrayWithObjects:@"How", @"are", @"you", nil];

    dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];

    for (id key in dictionary) {

        NSLog(@"key: %@, value: %@", key, [dictionary objectForKey:key]);




If you run the above code the following output will be shown on the console.

2009-07-29 15:42:34.634 DataTypes[560:10b] key: key1, value: How

2009-07-29 15:42:34.636 DataTypes[560:10b] key: key2, value: are

2009-07-29 15:42:34.639 DataTypes[560:10b] key: key3, value: you



Related Tags for NSLog NSDictionary Example code:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 29, 2009

Recommend the tutorial

Advertisements Advertisements