JSON データを個々のオブジェクトの配列に格納する際に問題が発生しています。JSONリクエストを処理しているdispatch_asynchの実行に問題があるようです。メソッドの前にブレークポイントを作成し、アプリケーションをステップ実行すると、dispatch_async に送信されたブロックを通り抜けるように見えます。
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSError *error = nil;
NSURL *url = [NSURL URLWithString:@"http://sleepy-dusk-3603.herokuapp.com/companies.json"];
NSString *json = [NSString stringWithContentsOfURL:url
encoding:NSASCIIStringEncoding
error:&error];
NSLog(@"\nJSON: %@ \n Error: %@", json, error);
if(!error) {
NSData *jsonData = [json dataUsingEncoding:NSASCIIStringEncoding];
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData
options:kNilOptions
error:&error];
NSArray *tempArray = [NSArray arrayWithObjects:@"Call Support Desk", @"Call Genius Bar", nil];
for (NSString *name in [jsonDict valueForKeyPath:@"name"]) {
NSString *tempString = [[NSString alloc] initWithString:name];
Company *company = [[Company alloc] initWithName:tempString available_actions:tempArray];
[self addCompany:company];
この問題に関する皆様のご支援とご支援に心から感謝いたします。