Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective-C: Why this function name caused a warning?
    text
    copied!<p>This is the original header file:</p> <pre><code>@interface TestDataHelper : NSObject { } +(void) populateTestData:(NSManagedObjectContext*) managedObjectContext; +(void) testPopulateTestData:(NSManagedObjectContext*) managedObjectContext; @end </code></pre> <p>When I compile this file, I got this warning:</p> <p><code>method definiton not found</code></p> <p>for testPopulateTestData</p> <p>When I ignore the warning and run the app in iphone simulator, I got a runtime exception:</p> <p><code>*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[TestDataHelper testPopulateTestData:]: unrecognized selector sent to class 0x104d8'</code></p> <p>Rename the method to 'test' alone seems to solve the problem</p> <p>What is special about <code>testXXX</code> method name?</p> <p><strong>EDIT:</strong> implementation is there and done. Renaming the method name (in both .h and .m) removes the warning, and the final app works.</p> <p><strong>EDIT 2</strong>:</p> <p>Here is the implementation of the function <code>test</code> (originally named as <code>testPopulatedTestData</code>):</p> <pre><code>+(void) test:(NSManagedObjectContext*) managedObjectContext { NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Stock" inManagedObjectContext:managedObjectContext]; [request setEntity:entity]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [request setSortDescriptors:sortDescriptors]; [sortDescriptors release]; [sortDescriptor release]; NSError *error = nil; NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&amp;error] mutableCopy]; NSEnumerator *e = [mutableFetchResults objectEnumerator]; id object; while (object = [e nextObject]) { // do something with object Stock* fc = (Stock*) object; NSLog(@"get a fc %s", [[fc name] description]); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload