Reputation: 4100
I am trying to determine the type of NSManagedObject I am dealing with. I do it in the following way:
NSManagedObject* object;
if ([[object entity].name isEqualToString:@"Folders"]){
Folders* folderObject = object;
}else if ([[object entity].name isEqualToString:@"AllFiles"]){
AllFiles* fileObject = object;
}
This method works, however i get a yellow error: incompatible pointer types initialising "AllFiles" with an expression of NSManagedObject. allFiles and Folders are subclasses of NSManagedObject.
Upvotes: 0
Views: 41
Reputation: 7560
It's not a "yellow error", but a warning :-)
You just have to cast the NSManagedObject to the right class to suppress the warning:
if ([[[object entity] name] isEqualToString:@"Folders"]) {
Folders *folderObject = (Folder *)object;
}
else if ([[[object entity] name] isEqualToString:@"AllFiles"]) {
AllFiles *fioleObject = (AllFiles *)object;
}
The debugger checks the object type and informs you that there is a mismatch. This could produce crashes. Since you know that the objects are subclasses of NSManagedObject
(the debugger doesn't) you can cast the object type to tell the debugger that all's fine.
Upvotes: 1