| From | Sent On | Attachments |
|---|---|---|
| Matt Reynolds | Sep 22, 2008 3:12 pm | |
| Duncan McGregor | Sep 22, 2008 3:15 pm | |
| Matt Reynolds | Sep 22, 2008 3:24 pm | |
| Duncan McGregor | Sep 24, 2008 3:03 pm | |
| Matt Reynolds | Sep 24, 2008 3:12 pm |
| Subject: | Re: Class hierarchies, NSArray, and casting | |
|---|---|---|
| From: | Matt Reynolds (ma...@hom3.us) | |
| Date: | Sep 22, 2008 3:24:16 pm | |
| List: | net.java.dev.rococoa.users | |
Yay! Sorry, I should have found that on my own. This works great!
Is there a way to add these sorts of examples into the wiki or some other place? I think they might be useful to people getting into Rococoa.
On Mon, Sep 22, 2008 at 3:16 PM, Duncan McGregor <dun...@oneeyedmen.com>wrote:
It looks like Rococoa.cast(NSObject object, Class<T> desiredType) should do it for you.
Duncan
On 22 Sep 2008, at 23:12, Matt Reynolds wrote:
I'm running this :
public class AddressBookTest { public static QTKit instance = (QTKit) Native.loadLibrary("AddressBook", QTKit.class);
/** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { System.out.println("Starting, instance created : " + instance); NSAutoreleasePool pool = NSAutoreleasePool.new_(); System.out.println("Java version : " + System.getProperty("java.version"));
_Class addressBookClass = ABAddressBook.CLASS; ABAddressBook addressBook = addressBookClass.sharedAddressBook(); NSArray people = addressBook.people(); System.out.println("People count : " + people.count()); for(int i = 0; i < people.count() ; i++) { NSObject objectAtIndex = people.objectAtIndex(i); System.out.println("Obj : " + objectAtIndex.getClass()); ABPerson person = (ABPerson) objectAtIndex; System.out.println("Person : " + person); }
pool.release(); System.out.println("Done"); } }
Currently, this fails because I can't cast NSObject to ABPerson because they're, well, not the same or in the same hierarchy. So, any tips on how I'd go about doing the above? I checked out JNA and didn't find a trick handy. Is this obvious and I'm missing it?





