JOAOSANTACRUZ.COM

Define and print, several types of variables, in Objective-C

Define and print, integer, boolean, strings and arrays, using Objective-C language


						

    // define a integer variable its value
    static NSUInteger vendorAge = 30;
    NSLog(@"The vendor age is: %d", vendorAge);
    
    
    // define a string variable and print its value
    static NSString *vendorName = @"MERCEDES BENZ";
    NSLog(@"The vendor name is: %@", vendorName);
    
    
    // define a boolean variable and print a strinf according to its value
    BOOL vendorIsExternal = YES;
    NSLog(vendorIsExternal ? @"Yes vendor Is External" : @"No vendor Is Not External");
   
    
    // define an array variable and print all its children - Example 1
    NSArray *vendorsArray =  [[NSArray alloc] initWithObjects:@"VOLKSWAGEN", vendorName, @"SKODA", @"OPEL", nil];

    // several types of printing the array content
    NSLog(@"The first value of the vendorsArray is: %@", [vendorsArray objectAtIndex:0]);
    NSLog(@"The secound value of the vendorsArray is: %@", [vendorsArray objectAtIndex:1]);
    NSLog(@"Listing all the elements of vendorsArray: %@", vendorsArray);
    
    
    

    // define an array using a for cycle and print all its children - Example 2
    NSMutableArray *vendorsAuxArray = [NSMutableArray array];
    // Ppopulate the array
    for (int i=0; i<5; ++i) {
        [vendorsAuxArray addObject:[NSString stringWithFormat:@"VENDOR %d", i]];
    }
    
    // several types of printing the array content
    NSLog(@"The first value of the vendorsAuxArray is: %@", [vendorsAuxArray objectAtIndex:0]);
    NSLog(@"The secound value of the vendorsAuxArray is: %@", [vendorsAuxArray objectAtIndex:1]);
    NSLog(@"Listing all the elements of vendorsAuxArray: %@", vendorsAuxArray);

    
  
    
    NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"AppConfig.plist"];
    NSDictionary* plotDictionary = [NSDictionary dictionaryWithContentsOfFile:path];


    
    // Gets string value from plist  file
    NSArray* name = [plotDictionary valueForKeyPath:@"AppName"];
    NSLog(@"the string to AppName key is: %@", name);
    
    // Gets an array value from plist  file
    NSArray* plotData = [plotDictionary objectForKey:@"DataPoints"];
    NSLog(@"Got the dict %d",[plotData count]);

    NSDictionary* plotPoint = [plotData objectAtIndex:1];
    NSLog(@"Got the point %d",[plotPoint count]);
    NSString* source = [plotPoint objectForKey:@"source"];
    NSLog(@"the value is: %@", source);

 

Go Back