So, I'm in a OS, Xcode application, in Objective-C code. Here's what I have so far:
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
/// IN THIS CHALLENGE, I HAVE TO MAKE MY OWN PLIST
/// IT HAS TO INCLUDE ALL 8 TYPES: ARRAY, DICTIONARY, STRING, DATA, DATE, INTEGER, FLOAT, AND BOOLEAN...
// Add the elements
NSMutableArray *array;
NSMutableDictionary *dictionary;
NSString *string;
NSData *data;
NSDate *date;
int integer;
float floating;
BOOL boolean;
// Set up the elements
[array addObject:[NSString stringWithFormat:@"\"Array\""]];
[dictionary setObject:@"\"Dictionary\""
forKey:@"dic"];
string = [NSString stringWithFormat:@"\"String\""];
data = [NSData dataWithContentsOfFile:@"/tmp/cool.text"];
date = [NSDate date];
integer = 50;
floating = 50.5;
boolean = YES;
// Log them out
NSLog(@"Array: %@\n\n", array);
NSLog(@"Dictionary: %@\n\n", dictionary);
NSLog(@"String: %@\n\n", string);
NSLog(@"Data: %@\n\n", data);
NSLog(@"Date: %@\n\n", date);
NSLog(@"Integer: %d\n\n", integer);
NSLog(@"Float: %f\n\n", floating);
NSLog(@"Boolean: %hhd\n\n", boolean);
}
return 0;
}
So, what this "challenge" (from a coding book I'm following) is supposed to do, is print out the values of each of these in the console. But, I have a problem here. When I run the application, the log prints out this:
2015-05-08 14:48:23.588 CHALLENGE 7. Plist[21817:1995500] Array: (null)
2015-05-08 14:48:23.590 CHALLENGE 7. Plist[21817:1995500] Dictionary: (null)
2015-05-08 14:48:23.590 CHALLENGE 7. Plist[21817:1995500] String: "String"
2015-05-08 14:48:23.590 CHALLENGE 7. Plist[21817:1995500] Data: <43687269 73746961 6e206973 20636f6f 6c210a43 68726973 7469616e 20697320 636f6f6c 210a4368 72697374 69616e20 69732063 6f6f6c21 0a436872 69737469 616e2069 7320636f 6f6c210a 43687269 73746961 6e206973 20636f6f 6c210a43 68726973 7469616e 20697320 636f6f6c 210a4368 72697374 69616e20 69732063 6f6f6c21 0a436872 69737469 616e2069 7320636f 6f6c210a 43687269 73746961 6e206973 20636f6f 6c210a43 68726973 7469616e 20697320 636f6f6c 21>
2015-05-08 14:48:23.596 CHALLENGE 7. Plist[21817:1995500] Date: 2015-05-08 19:48:23 +0000
2015-05-08 14:48:23.596 CHALLENGE 7. Plist[21817:1995500] Integer: 50
2015-05-08 14:48:23.596 CHALLENGE 7. Plist[21817:1995500] Float: 50.500000
2015-05-08 14:48:23.597 CHALLENGE 7. Plist[21817:1995500] Boolean: 1
So, this is OK, but I'd like some help on how to use the NSLog() to print out the values correctly. As you can see, both the array and the dictionary are printed out as (null), or rather, with no value. And the data from a file containing the words "Random Text" doesn't print out the String value. It seems to print out the non-human-readable value of the file itself. Is it because I used the %@ token with these? If so, what should I use?