Why doesn't NSOrderedSet inherit from NSSet?
问题 Surely an ordered set is a more-specific case of a set, so why does NSOrderedSet inherit from NSObject rather than NSSet ? 回答1: I went through the interface of NSSet and you're right, ordered sets appear to satisfy the Liskov substitution principle and could therefor inherit from NSSet . There is one little method that breaks this: mutableCopy . The return value of mutableCopy must be an NSMutableSet , but NSMutableOrderedSet should inherit from NSOrderedSet . You can't have both. Let me