How do I create the CFErrorRef parameter required for modifying ABAddressBook via Ruby Motion
-
11-06-2021 - |
Domanda
I'm trying to use Ruby Motion to add an entry to the AddressBook. I can't figure out how to properly instantiate the CFErrorRef parameter.
error = nil # compiles but won't capture an error properly
# Here are my numerous attempts:
#error = Pointer.new( :object ) expected instance of Pointer of type `^{__CFError}', got `@' (TypeError)
#error = Pointer.new( '^{__CFError}' ) Can't find pointer description for type `^{__CFError}'
#error = Pointer.new( '{__CFError}' ) Can't find pointer description for type `{__CFError}'
#error = Pointer.new( '__CFError' ) Can't find pointer description for type `__CFError'
#error = Pointer.new( CFError.type ) uninitialized constant AppDelegate::CFError (NameError)
#error = Pointer.new( CFErrorRef.type ) uninitialized constant AppDelegate::CFErrorRef
p = ABPersonCreate()
raise error[0] unless ABRecordSetValue( p, KABPersonFirstNameProperty, "Guy", error )
raise error[0] unless ABRecordSetValue( p, KABPersonLastNameProperty, "Argo", error )
ab = ABAddressBookCreate()
raise error[0] unless ABAddressBookAddRecord( ab, p, error )
raise error[0] unless ABAddressBookSave( ab, error )
NSLog( "Record successfully added." )
Suggestions welcome. Guy
Soluzione
Upgrading to RubyMotion 1.9 includes this fix:
- Fixed a bug in the compiler where APIs accepting pointers to CoreFoundation types could not be given Pointer objects of the :object type (ex. CFErrorRef*).
sudo motion update
will get this for you.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow