I'm curious to know if any of the Cocoa frameworks contain an initializer that might be mistaken for dealing with a human being. Obvious methods, (although I don't know if or where they exist) are initWithAge
, or initWithName
.
Are there any really clever sounding Cocoa initializers that may be applicable to people?
Edit:
I'm certainly not asking about the new
operator. This is the kind of question you might get at a trivia event, but I'm absolutely serious about this. It can be answered objectively and definitively. Are there any cleverly named Cocoa initializers that can be understood to refer to people?
So, I think you're asking this:
Is there an established convention for initializing an object that describes a person?
So, the first thing I would do is grep through the framework headers looking for references to "person":
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks
$ grep -r 'Person\b' . | edit
(Yes, I default to looking in the Mac SDK. Looking in the iOS SDK will be left as an exercise to the reader)
This results in 381 hits for me, mostly duplicated information. But there are a couple of interesting hits:
ABPerson
from AddressBook.frameworkEKParticipant
from EventKitPSAuthor
from PubSubUnfortunately, none of these results have an initializer, because they're all mainly for interacting with existing Person objects, not for creating new ones. The exception is -[ABPerson(ABPerson_vCard) initWithVCardRepresentation]
. That's probably not helpful.
So we need to keep digging. How else might we describe a person? "People"? "Member"? "Individual"? "Customer"? All of these would be pretty good things to look for.
And then I remembered that there's this obscure framework buried deep inside the OS X SDK that no one ever really talks about, called Collaboration.framework:
The Collaboration framework is a set of Objective-C classes that allows developers to monitor identities and their attributes. (reference)
That looks promising! And indeed, looking in here there's really interesting class: CBIdentity
. A CBIdentity
"is used for accessing the attributes of an identity". There are a bunch of different ways to create an identity, but I like this pattern, and I would recommend doing it like this:
An "MBIdentity" class would define ways to canonically identify a person. So you could have -initWithSocialSecurityNumber:
or -initWithName:
or -initWithBirthLocation:time:
, etc. The purpose of this class would be to establish a collection of attributes that are sufficient to identify an individual.
Your "MBPerson" class would then have an -initWithIdentity:
method that takes an MBIdentity
. The Person would then take on the characteristics of its composed Identity.
I suppose the important thing to realize here is that there are many ways to establish identity (and hence many properties/initializers on an MBIdentity
). But once you've established an identity, only one Person has that identity (and so your Person
class only has an initWithIdentity:
method).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With