Problem with returning values from a custom array class...

Hello,

I have an array with various columns (First name, last name, gender, department, etc.) and I created a custom class that will merge the first and last name into one non-editable column, and it works fine until I bind the table’s array controller to a variable in the user defaults, it give this error:

*** -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '(
{
},
"<NewDocStaffDBClass @0x200686b20: OSAID(205)>

If it is not bound to the user defaults, it behave fine, but the contents are obviously not saved. If I do not use this class, it works fine. Although the result is returned as a string, maybe something is wrong when it attemps to return it to the main script?

From what I have seen on the web with this error, it may be the case. Any ideas?

This is the class I am using to merge the first and last names:

script NewDocStaffDBClass
	property parent : class "NSObject"
	
	property firstName : "" as string
	property lastName : "" as string
	property gender : 0 as integer
	property extensionNumber : "" as string
	property department : 0 as integer
	
	on completeName()
		if my firstName = missing value then set my firstName to ""
		if my lastName = missing value then set my lastName to ""
		return (((my firstName as string) & " " & (my lastName as string)) as string)
	end completeName
end script

Thanks!

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

Hi,

NSUserDefaults supports only the classes NSString, NSNumber, NSArray, NSDictionary, NSDate and NSData.
A custom class object can be stored by using archiving/unarchiving, which converts the class object into NSData.
Your custom class must conform to the protocol

Alright, thanks, this confirms my doubts.

How do I make the class conform to NSCoding protocol? Do I change the parent property from NSObject to NSCoding?

And this archiving/unarchiving, I use the “NSUnarchiveFromData” as the Value transformer, correct? Won’t it affect the other data though? I have strings and numbers too, well actually technically there should only be strings and numbers…

Regards,
Fred

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

I don’t know how to do this in ASOC but in Cocoa the protocol(s) are listed in the @interface line after the class name
e.g. NSObject .

The protocol requires the methods


-(id)initWithCoder:(NSCoder*)coder;
-(void)encodeWithCoder:(NSCoder*)coder;

See the documentation for further details

Well, that’s a bit more work than I thought, and my knowledge of Obj-C is too limited for the moment. Sad, because for such a simple result, this seems overly complex… I think I’ll try to do a repeat loop and filter the data and save it reformatted in ASOC…

Thanks for the info though!

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)