But what do I put in that array? The initWithKeysToFetch(NSArray<?> keysToFetch) signature doesn’t specify a generic type. I noticed that the keys in my example are all variables of the Contacts.java and they are returned as String. Does that mean I can just insert Strings and use NSArray< String>?
Also, if I start allocating variables like this, do I need to dealloc() them whenever I am done with them? Or is there some kind of garbage collection for variables I allocate and initialize within a method.
A lot of types are “hidden” when working with MOE from what I’ve seen, so you’ll encounter a lot of “?”. A quick way to know what the real type of a variable/return value is is to just add a breakpoint and check in the debugger.
If you use a simple NSArray, you’ll get an UnsupportedOperationException when trying to add() or remove(). you need a Mutable one for this (I imagine that’s what you want to do). I just stumbled upon this issue an hour ago haha.
I don’t know if it’s the best way of doing things but it works. You can’t insert Strings into a NSArray<?>, first because it’s not mutable and because you can’t insert a specific type into a ? type. ? is an upper-bounded wildcard.
As for dealloc(), someone correct me if I’m wrong but from what I’ve read in the NatJ documentation, it’s done automatically by the garbage collector. You don’t have to manually call dealloc() when you alloc
I’ll try something like this when I get home and let you know if this works as I expect it should: NSArray<?> array = NSArray.arrayWithObjects("CNContactEmailAddressesKey", "CNContactPhoneNumbersKey");
Yes that works if you already know what you’ll be putting inside of it, in this case you can even take a NSArray instead of <?>, as using arrayWithObjects() will return an NSArray with the type of the objects you passed as parameters