views:

33

answers:

1

Edit: 10-9-10 I think the app is crashing when the JSON library tries to parse the [NSString stringWithFormat:@"%d weeks",[components week]] How would i format it so that JSON can parse it?

here's the JSON code line

NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
        NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                              kAppId, @"api_key",
                               @"Share on Facebook",  @"user_message_prompt",
                               actionLinksStr, @"action_links",
                              attachmentStr, @"attachment",
                               nil];

can anyone point me to a tutorial on how to do this? I can easily post the static text in the code block below but i can't integrate an NSString with dynamic data, it doesn't show up on the Fb post attachment section.

 NSDictionary *attachment = [NSDictionary dictionaryWithObjectsAndKeys:
                        @"Testing", @"name",
                         @"testing2", @"caption",
                          [NSString stringWithFormat:@"%d weeks",[components week]], @"description"//Xcode says components undeclared 

//highscore, @"description", //here's the problem, highscore is the NSString variable.
                          @"http://testing.com/", @"href", nil];

Update: the problem is the string i'm using is from a time interval of the difference of 2 weeks and the out put is [components week] and then xcode tells me components is an undeclared variable

[NSString stringWithFormat:@"%d weeks",[components week]]

here's the whole date code block that i get the string above from:

NSString *dateStr = @"20100716";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyyMMdd"];
NSDate *startDate = [dateFormat dateFromString:dateStr]; 
NSDate *endDate = [NSDate date];

NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];

NSUInteger unitFlags = NSWeekCalendarUnit | NSDayCalendarUnit;

NSDateComponents *components = [gregorian components:unitFlags
fromDate:startDate
toDate:endDate options:0];

NSInteger weeks = [components week];
NSInteger days = [components day];
A: 

Try stringWithFormat [NSString stringWithFormat:@"%@", highscore]; instead of highscore

Rajani Karuturi
I tried that string format and it just crashes the app
BigB