DRYな備忘録

Don't Repeat Yourself.

【iOS】NSDictionaryからlongを取り出す

ゴール

以下のようなNSDictionaryから"Timestamp"をlongとして値を取り出したい

// *dict
{
    Number = 1408756029;
    Message = "hogeee";
}

解決

NSDictionaryobjectForKeyを使ってから、longLongValueでキャストする

long num = [[dict objectForKey:@"Finish"] longLongValue];

ちなみにNSIntegerとして欲しかったら同様に、integerValueを使う

NSInteger num = [[dict objectForKey:@"Finish"] integerValue];

DRYな備忘録