これは私の頭のてっぺんから外れていて、テストされていません:
NSThread+ManyObjects.h
:
@interface NSThread (ManyObjects)
+ (void)detachNewThreadSelector:(SEL)aSelector
toTarget:(id)aTarget
withObject:(id)anArgument
andObject:(id)anotherArgument;
@end
NSThread+ManyObjects.m
:
@implementation NSThread (ManyObjects)
+ (void)detachNewThreadSelector:(SEL)aSelector
toTarget:(id)aTarget
withObject:(id)anArgument
andObject:(id)anotherArgument
{
NSMethodSignature *signature = [aTarget methodSignatureForSelector:aSelector];
if (!signature) return;
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:aTarget];
[invocation setSelector:aSelector];
[invocation setArgument:&anArgument atIndex:2];
[invocation setArgument:&anotherArgument atIndex:3];
[invocation retainArguments];
[self detachNewThreadSelector:@selector(invoke) toTarget:invocation withObject:nil];
}
@end
そして、インポートNSThread+ManyObjects
して呼び出すことができます
[NSThread detachNewThreadSelector:@selector(loginWithUser:user:password:) toTarget:self withObject:@"someusername" andObject:@"somepassword"];