objc bridge problem with (macosx) addressbook api
This is what I want to do:
+--
ABAddressBook *addressBook;
ABPerson *newPerson;
addressBook = [ABAddressBook sharedAddressBook];
newPerson = [[ABPerson alloc] init];
[newPerson setValue:@"John"
forProperty:kABFirstNameProperty];
[newPerson setValue:@"Doe"
forProperty:kABLastNameProperty];
[addressBook addRecord:newPerson];
[addressBook save];
+--
from
https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AddressBook/Tasks/ManagingGroups.html#//apple_ref/doc/uid/20001022-BABHHIHC
I tried to translate into this:
+--
(objc:ensure-objc-initialized
:modules
'("/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation"
"/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa"
"/System/Library/Frameworks/AddressBook.framework/Versions/Current/AddressBook"))
(defun addressbook-create-person (firstname)
"Calls Addressbook via LW objc-bridge"
(let ((pool (objc:alloc-init-object "NSAutoreleasePool")))
(unwind-protect
(let ((addressbook (objc:invoke "ABAddressBook"
"sharedAddressBook")))
(if addressbook
(let ((person (objc:invoke (objc:invoke "ABPerson" "alloc")
"initWithAddressBook:" addressbook)))
(if person
(progn
;; the following line crashes LW
(objc:invoke person "setValue:forProperty:"
(objc:invoke "NSString" "stringWithString:" firstname)
"kABFirstNameProperty")
(objc:invoke addressbook "save"))
(error "can't create person")))
(error "can't create shared addressbook")))
(progn
(objc:invoke pool "drain")))))
+--
While trying to set the firstname property of my freshly created person
my LW session crashes noiseless. When I remove the offending line a
person without properties is visible in my Mac Addressbook.
Obviously I am not allowed to insert a simple Lisp string at the
position where Objective-C expects an (id) type. But what kind of
pointer-foo do I have to do to get it right?
thanks
jens
_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html