Tuesday, May 7, 2013

NSDictionary descriptionInStringsFileFormat example ios


descriptionInStringsFileFormat

Returns a string that represents the contents of the dictionary, formatted in .strings file format.
- (NSString *)descriptionInStringsFileFormat
Return Value of [NSDictionary descriptionInStringsFileFormat]
A string that represents the contents of the dictionary, formatted in .strings file format.
Discussion
The order in which the entries are listed is undefined.
Example of [NSDictionary descriptionInStringsFileFormat]
+ (NSDictionary *)dictionaryFromPropertyListString:(NSString *)stringToParse
{
    NSLog(@"dictionaryFromPropertyListString: %@", stringToParse);

    NSString *newFilePath = [NSTemporaryDirectory() stringByAppendingString:@"/Stuff.plist"];

    [stringToParse writeToFile:newFilePath atomically:YES encoding:NSASCIIStringEncoding error:nil];

    NSDictionary *dictionaryToReturn = [NSDictionary dictionaryWithContentsOfFile:newFilePath];

    NSLog(@"returned dictionary: %@", [dictionaryToReturn descriptionInStringsFileFormat]);

    return dictionaryToReturn;
}
Example of [NSDictionary descriptionInStringsFileFormat]
- (void) recordTransaction: (SKPaymentTransaction *) transaction {
    NSDictionary * receipt = [transaction.transactionReceipt dictionaryFromAppleResponse];
    NSDictionary * purchaseInfo = [[NSData dataFromBase64String: [receipt objectForKey: @"purchase-info"]] dictionaryFromAppleResponse];

    NSURL * url = [NSURL URLWithString: @"http://..."];

    ASIFormDataRequest * request = [ASIFormDataRequest requestWithURL: url];
    [request setDelegate: self];

    [request setPostValue: [NSNumber numberWithBool: YES] forKey: @"upload"];
    [request setPostValue: [[[NSBundle mainBundle] infoDictionary] objectForKey: @"CFBundleDisplayName"] forKey: @"app_id"];
    [request setPostValue: [receipt descriptionInStringsFileFormat] forKey: @"receipt"];
    [request setPostValue: [purchaseInfo descriptionInStringsFileFormat] forKey: @"purchase_info"];

    [WTFeedbackView switchToProgressView];

    NSLog(@"Before -startAsynchronous call.");
    [request startAsynchronous];
    NSLog(@"After  -startAsynchronous call.");
}