|
From: Rupert B. <rup...@fr...> - 2005-11-04 20:54:19
|
OK, here is the final results of the experiment.
With this code ...
class Employee < OSX::NSManagedObject
include OSX
=09
@@lastID =3D 123
kvc_accessor :lastName, :firstName, :employeeID
kvc_depends_on([ :lastName, :firstName, :employeeID ], =
:fullNameAndID)
def initialize
rbSetValue_forKey(NSNumber.numberWithInt(@@lastID), =
"employeeID")
puts "*** =
rbSetValue_forKey(NSNumber.numberWithInt(@@lastID), =20
\"employeeID\") : #{rbValueForKey("employeeID")} ***"
end
def fullNameAndID
puts "*** self =3D #{self} ***"
puts "*** rbValueForKey(\"employeeID\") =3D =
#{rbValueForKey=20
("employeeID")} ***"
end
end
... I get the following output ...
*** rbSetValue_forKey(NSNumber.numberWithInt(@@lastID), =20
"employeeID") : 123 ***
*** self =3D <Employee: 0x557eb0> (entity: Employee; id: 0x55a950 <x-=20
coredata:///Employee/t31E6B1EE-8E9F-4E1A-BA1E-47CA62FEBF3D> ; data: {
department =3D nil;
directReports =3D ();
employeeID =3D nil;
firstName =3D First;
lastName =3D Last;
manager =3D nil;
salary =3D 0;
}) ***
*** rbValueForKey("employeeID") =3D 123 ***
I am setting the employeeID correctly (through setValue), but the =20
value is not 'arriving' in the coredata object. However, it is not =20
lost, because I re-read from in another method (fullNameAndID) with =20
the valueForKey method.
Any ideas ?
Rup
Le 4 nov. 05 =C3=A0 21:32, Rupert Barrow a =C3=A9crit :
> Jonathan,
>
> Thanks for answering quickly.
>
> I removed definition of the @firstName and @lastName attributes, =20
> and it worked..
>
> After studying your answer, I noticed the following :
> ' kvc_accessor :lastName, :firstName'
> creates these methods :
> firstName
> firstName=3D
> lastName
> lastName=3D
>
> If I comment out this code, the methods disappear. When I dump =20
> Employee, I see the "attributes" :
> *** Employee =3D <Employee: 0x3ff5b0> (entity: Employee; id: 0x53f370 =20=
> <x-coredata:///Employee/tFE462E87-F74A-4826-8487-7C16DBECD891> ; =20
> data: {
> department =3D nil;
> directReports =3D ();
> employeeID =3D nil;
> firstName =3D First;
> lastName =3D Last;
> manager =3D nil;
> salary =3D 0;
> }) ***
> but when I try to access them, the methods are obviously undefined :
> 2005-11-04 21:25:56.696 DepartmentAndEmployees[789] Exception =20
> raised during posting of notification. Ignored. exception: =20
> undefined method `lastName' for class `Employee'
>
> So :
> - kvc_depends_on declares and uses one set of accessors
> - CoreData relies on another access/update method : through =20
> setValue:forKey: and valueForKey:, as you mentioned.
>
> Would it not be nice to 'merge' them both, so as not to have to =20
> handle to access/update methods for the same data ?
>
> Rup
>
>
> Le 4 nov. 05 =C3=A0 00:13, Jonathan Paisley a =C3=A9crit :
>
>> On 3 Nov 2005, at 21:31, Rupert Barrow wrote:
>>
>>> class Employee < OSX::NSManagedObject
>>> include OSX
>>>
>>> attr_accessor :firstName
>>> attr_accessor :lastName
>>>
>>> kvc_accessor :lastName, :firstName
>>> kvc_depends_on([ :lastName, :firstName], :fullNameAndID)
>>>
>>> def initialize
>>> @firstName =3D "MyFirst"
>>> @lastName =3D "MyLast"
>>> end
>>>
>>
>> [Let me say first that I've not used Core Data yet, so this is my =20
>> understanding from glancing over the documentation. Please correct =20=
>> any misunderstanding!]
>>
>> Since you're using Core Data, all the data members of the class =20
>> are already managed for you. Therefore, you should not define =20
>> firstName and lastName as accessors, nor should you use ruby =20
>> @firstName/@lastName variables.
>
|