Amazon.com Widgets Chapter 16 Exercise 8
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 22, 2013, 04:31:15 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Programming in Objective-C, 4th edition
| |-+  Exercises
| | |-+  Chapter 16
| | | |-+  Chapter 16 Exercise 8
Pages: [1]   Go Down
Print
Author Topic: Chapter 16 Exercise 8  (Read 326 times)
clouded
Full Member
***
Posts: 123






« on: June 29, 2012, 08:41:20 AM »

Tried keeping it simple on this one, here's what I did:

Code: (Objective-C)
//  main.m
//  Chapter 16 Exercise 8
// A dictionary is stored as a property list at this URL:http://bit.ly/aycNwd.
// Write a program to read the contents of this dictionary and display
// its contents. What data does the dictionary contain?

#import <Foundation/Foundation.h>

int main (int argc, char * argv[])
{
    @autoreleasepool {
        
        // Input URL's information into info

        NSMutableDictionary *info = [NSMutableDictionary dictionaryWithContentsOfURL: [NSURL URLWithString: @"http://bit.ly/aycNwd"]];
        
        // Display info

        NSLog(@"In original sorted state:");
        for (NSString *key in info) {
            NSLog(@"%@: %@", key, [info objectForKey: key]);
        }
        
        // Place info into ascendingOrder for sorting

        NSArray *ascendingOrder = [info allKeys];
        ascendingOrder = [ascendingOrder sortedArrayUsingComparator: ^(id obj1, id obj2) { return [obj1 compare: obj2]; } ];
        
        // Display ascendingOrder

        NSLog(@" ");
        NSLog(@"In ascending sorted state:");
        for (NSString *state in ascendingOrder) {
            NSLog(@"%@: %@", state, [info objectForKey: state]);
        }
    }
    return 0;
}

Output:

In original sorted state:
Utah: Salt Lake City
South Carolina: Columbia
West Virginia: Charleston
Arizona: Phoenix
Kansas: Topeka
Minnesota: St. Paul
Florida: Tallahassee
Idaho: Boise
Washington: Olympia
Hawaii: Honolulu
New York: Albany
Montana: Helena
Nevada: Carson City
Mississippi: Jackson
North Dakota: Bismarck
Iowa: Des Moines
Georgia: Atlanta
Ohio: Columbus
Nebraska: Lincoln
Missouri: Jefferson City
Alabama: Montgomery
Maine: Augusta
New Hampshire: Concord
Alaska: Juneau
Arkansas: Little Rock
North Carolina: Raleigh
Texas: Austin
South Dakota: Pierre
Massachusetts: Boston
Connecticut: Hartford
Louisiana: Baton Rouge
Wyoming: Cheyenne
Illinois: Springfield
Maryland: Annapolis
Vermont: Montpelier
Wisconsin: Madison
Delaware: Dover
New Jersey: Trenton
Colorado: Denver
Oklahoma: Oklahoma City
California: Sacramento
Oregon: Salem
Tennessee: Nashville
Indiana: Indianapolis
Michigan: Lansing
New Mexico: Santa Fe
Rhode Island: Providence
Pennsylvania: Harrisburg
Kentucky: Frankfort
Virginia: Richmond
 
In ascending sorted state:
Alabama: Montgomery
Alaska: Juneau
Arizona: Phoenix
Arkansas: Little Rock
California: Sacramento
Colorado: Denver
Connecticut: Hartford
Delaware: Dover
Florida: Tallahassee
Georgia: Atlanta
Hawaii: Honolulu
Idaho: Boise
Illinois: Springfield
Indiana: Indianapolis
Iowa: Des Moines
Kansas: Topeka
Kentucky: Frankfort
Louisiana: Baton Rouge
Maine: Augusta
Maryland: Annapolis
Massachusetts: Boston
Michigan: Lansing
Minnesota: St. Paul
Mississippi: Jackson
Missouri: Jefferson City
Montana: Helena
Nebraska: Lincoln
Nevada: Carson City
New Hampshire: Concord
New Jersey: Trenton
New Mexico: Santa Fe
New York: Albany
North Carolina: Raleigh
North Dakota: Bismarck
Ohio: Columbus
Oklahoma: Oklahoma City
Oregon: Salem
Pennsylvania: Harrisburg
Rhode Island: Providence
South Carolina: Columbia
South Dakota: Pierre
Tennessee: Nashville
Texas: Austin
Utah: Salt Lake City
Vermont: Montpelier
Virginia: Richmond
Washington: Olympia
West Virginia: Charleston
Wisconsin: Madison
Wyoming: Cheyenne
« Last Edit: June 29, 2012, 09:32:37 AM by clouded » Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.