Facebook Graph呼び出しを行い、いくつかの項目を配列に追加しようとしています。項目はforループに追加され、配列は正常に見えます。しかし、forループの後、アイテムは消えます。
FacebookSDK3.1でxcode4.5を使用しています。
私は何を取りこぼしたか?
TableViewController.m
#import "TableViewController.h"
@interface TableViewController ()
@end
@implementation TableViewController {
NSMutableArray *recipes;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
recipes = [NSMutableArray arrayWithObjects:@"Egg Benedict", nil];
[recipes addObject:@"foobar"];
NSLog(@"recipes before FBRquestConnection: %@", recipes);
[FBRequestConnection
startWithGraphPath:@"search?type=place¢er=37.785834,-122.406417"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (!error) {
for (id item in [result objectForKey:@"data"]) {
[recipes addObject:[item objectForKey:@"name"]];
}
NSLog(@"recipes after for-loop: %@", recipes);
NSLog(@"amount of recipes after for-loop: %u", [recipes count]);
}
}];
NSLog(@"amount of recipes after FBRequestConnection: %u", [recipes count]);
}
デバッグコンソール出力
2012-12-27 23:09:44.056 barbar[3481:19a03] recipes before FBRquestConnection: (
"Egg Benedict",
foobar
)
2012-12-27 23:09:44.056 barbar[3481:19a03] amount of recipes after FBRequestConnection: 2
2012-12-27 23:09:44.516 barbar[3481:19a03] recipes after for-loop: (
"Egg Benedict",
foobar,
"Union Square, San Francisco",
"Benefit Cosmetics",
"San Francisco | The Official Guide",
"BareMinerals by Bare Escentuals",
"Viator.com",
"Bleacher Report",
"Downtown San Francisco",
"AMC Metreon 16",
"Cheesecake Factory",
SquareTrade,
"Westfield San Francisco Centre",
"Bloomingdale's San Francisco",
"Macy's San Francisco Union Square",
Xoom,
"Parc 55 Hotel",
"Pottery Barn",
"AT&T Park",
Bebo,
Snapfish,
"Hilton San Francisco Union Square",
uTorrent,
"The Westin St. Francis",
TRUSTe,
"Apple Retail Store - San Francisco"
)
2012-12-27 23:09:44.516 barbar[3481:19a03] amount of recipes after for-loop: 26
乾杯-ジェリック