NSArray
またはNSDictionary
のラッパーオブジェクトを作成し、そのラッパーオブジェクトを渡して渡す必要がある複数のオブジェクトをuserInfo
に作成します。受信側では、オブジェクトをラッパーオブジェクトから取得します。
ラッパーのためのNSDictionaryのを使用して
コード例:
電話番号:
NSString *obj1 = @"string1";
NSString *obj2 = @"string2";
NSDictionary *wrapper = [NSDictionary dictionaryWithObjectsAndKeys:obj1, @"Object1", obj2, @"Object2", nil];
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerFireMethod:) userInfo:wrapper repeats:NO];
受信タイマーコード:
- (void)timerFireMethod:(NSTimer*)theTimer {
NSDictionary *wrapper = (NSDictionary *)[theTimer userInfo];
NSString * obj1 = [wrapper objectForKey:@"Object1"];
NSString * obj2 = [wrapper objectForKey:@"Object2"];
// ...
}