Hacker News new | ask | show | jobs
by scrumper 4913 days ago
Any use cases for Nil, that is, the class pointer to nothing? I've not seen it in the wild (which isn't saying a great deal.)
1 comments

You could use it to test whether or not you really got a class from NSClassFromString(). For instance:

  Class _myClass;
  // aClassName was previously defined
  if((_myClass = NSClassFromString(aClassName)) == Nil)
     [NSException raise:@"InvalidClass" 
                 reason:@"Unknown class named %@.", aClassName);
  
  id myObj = [[_myClass alloc] init];
  [myObj whatever];
Makes sense, thanks.