When a pointer has no object points to, it's automatically storing the value 0, which we call a NIL pointer. And, we can complete our other designs without checking the pointer is NIL or not because that function calls just do nothing on NIL pointers, and return 0.
Take one example I learned in the class,
if ([card.contents isEqualToString:self.contents] ){ score = 1; }No need to card.contents is NIL or not. If it's NIL, isEqualToString just simply skip it and return 0, which may cause the if-statement failed, which is also the right thing we want.
No comments:
Post a Comment