Reputation: 1655
In the below excerpt,
/*A ClassName with instanceMethod and ClassMethod */
-(void)instanceMethod;
+(void)ClassMethod;
/*To call a instance method in background */
ClassName class1obj = [ClassName alloc] init];
[class1obj performSelectorInBackground:@selector(instanceMethod) withObject:nil];
Similarly, how to call a ClassMethod in background using performSelectorInBackground
?
If possible, please explain! Please guys join hands ..
Upvotes: 12
Views: 2135
Reputation: 52592
You should look at GCD (Grand Central Dispatch), which solves the general problem "How to execute code in the background". Doesn't matter whether it's calling a class method, calling an instance method, throwing dice, writing to a file, whatever.
Example:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog (@"This is code running in the background");
[MyClass someClassMethod];
[myInstance someMethodWithInt:1 bool:YES string:@"some string"];
NSLog (@"Finished with the background code");
});
Works with arbitrary code; no need to use selectors, no need to write methods just to have a selector to run in the background, no need to turn parameters into NSObject (you can't use performSelector with an int or BOOL argument). Xcode will fill out most of this for you automatically.
Upvotes: 1
Reputation: 184
please try self
instead of class name
[self performSelectorInBackground:@selector(methodTobeCalled) withObject:nil];
hope this wil work for you
Upvotes: 2
Reputation: 877
Just call
[ClassName performSelectorInBackground:@selector(ClassMethod) withObject:nil];
Because Classes are objects themselves, this will work.
Upvotes: 18