New Person class
Subclass of Person Student
Teacher
Today I think of the database encapsulation, because the query results are inherited from Nsmanagerobject, but his sub-class properties are not necessarily the same, so I think I can not judge after the query that he is the subclass and according to the properties of the subclass to assign values, So first I want the class of the object to be stored in the array to judge
The test is as follows: (the main code to contribute as follows, other documents to suggest it, very simple)
Nsmutablearray * array = [nsmutablearrayarray];
nsmutablearray * array2 = [nsmutablearrayarray];
for (int i =0; i< 5; i++) {
Student * stu1 = [[Studentalloc]init];
Stu1. name =[nsstringstringwithformat:@ "jack%i", I];
[Arrayaddobject: STU1];
Teacher * Teacher = [[Teacheralloc]init];
Teacher. name = [nsstringstringwithformat:@ "limei%i", I];
[Array2addobject: teacher];
}
for ( Person * p in array) {
NSLog (@ "%@------", p.class);
}
for ( Person * p in Array2) {
NSLog (@ "%@------", p.class);
}
// from the printed result it can be seen that although I receive it with his parent class, the. class can still display the subclass name so that the object traversed from the array I can use . class to get what kind of child he is, and decide how to assign him a value.
For example
for ( Person * p in Array2) {
if (p.class = = [Studentclass]) {
NSLog (@ " is a student ");
}Else {
NSLog (@ " not a student ");
}
}
if ([array[0]class] = = [Studentclass]) {
NSLog (@ " is a student ");
}Else{
NSLog (@ " not a student, is %@", [array[0]class]);
}
iOS CoreData receives an array of subclasses with the instance object of the parent class, prints the Person.class, and the result is the subclass class name? Or is the parent class name (resolved) iOS CoreData with the instance object of the parent class the person receives an array that has subclasses, prints the Person.class, and the result is the subclass class name? Or is the parent class name (resolved) iOS CoreData with the instance object of the parent class the person receives an array that has subclasses, prints the Person.class, and the result is the subclass class name? Or is the parent class name (resolved) iOS CoreData with the instance object of the parent class the person receives an array that has subclasses, prints the Person.class, and the result is the subclass class name? or the parent class name (resolved)
iOS CoreData receives an array of subclasses with the instance object of the parent class, prints the Person.class, and the result is the subclass class name? or the parent class name (resolved)