8. Программирование на Objective-C. Массивы и словари



#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    @autoreleasepool
    {
        int theArray[] = {5, 0, 1, 2, 3, 4};
        while (theArray[0])
        {
            NSLog(@"%i\n", theArray[theArray[0]--]);
        }
        
        
        NSString *pets[3] = {@"cat", @"dog", @"cock"};
        NSLog(@"%@", pets[0]);
        
        
        NSArray *theMyArray = [[NSArray alloc] initWithObjects:@"name", @"family", nil];
        for (int i = 0; i < theMyArray.count; i++)
        {
            NSLog(@"%@", [theMyArray objectAtIndex:i]);
        }
        
        NSArray *theOtherArray = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
        for (NSString *theElement in theOtherArray)
        {
            NSLog(@"%@\n", theElement);
        }
        
        NSMutableArray *theMutableArray = [[NSMutableArray alloc] init];
        [theMutableArray addObject:@"test"];
        NSLog(@"%@", [theMutableArray objectAtIndex:0]);
        [theMutableArray removeObjectAtIndex:0];
        NSLog(@"%lu", theMutableArray.count); // 0
        
        NSDictionary *theDomains = [NSDictionary dictionaryWithObjectsAndKeys:@"Russia", @"ru", @"Kazakhstan", @"kz", @"USA", @"us", nil];
        NSLog(@"%@", [theDomains objectForKey:@"ru"]);
        
        NSMutableDictionary *theMutableDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"One", "1", nil];
        [theMutableDictionary setObject:@"Two" forKey:@"2"];
    }
    return 0;
}