I have been working my way through an example of binding two tables together and although I have followed the instructions carefully I keep getting an error concerning NSCFArray error about the object not being created.
I think it may have to do with how the array is formed but cannot solve it.
Can someone advise me of the correct way to form an array and a dictionary:
I have tried:
tell class "NSArray" of current application to set pKeys to its arrayWithObjects_("title", missing value)
tell class "NSArray" of current application to set pValues to its arrayWithObjects_("New Account", missing value)
tell class "NSMutableDictionary" of current application to set pProperties to its initWithObjects_forKeys_(pValues, pKeys)
tell class "NSMutableArray" of current application to set pTransactions to its alloc's init()
also
set pKeys to NSArray's arrayWithObjects__("title", missing value)
set pValues to NSArray's arrayWithObjects_("New Account", missing value)
set pProperties to NSMutableDictionary's initWithObjects_forKeys_(pValues, pKeys)
set pTransactions to NSMutableArray's allocs's init()
also
set pProperties to {title:"New Account"}
set pTransactions to {}
Are Applescript lists fully interchangeable with NSArray and NSMutableArray?
Are Applescript records fully interchangeable with NSDictionary and NSMutableDictionary?
This is the example project I created with Shane’s help for binding two tables without using any NSMutableArray stuff, just a simple record. So far it seems to work. There are only a few lines of code but the settings for the bindings have to be EXACTLY as they are for it to work. I would be glad to help walk you through it.
tell class "NSMutableDictionary" of current application to set pProperties to its initWithObjects_forKeys_(pValues, pKeys)
tell class "NSMutableArray" of current application to set pTransactions to its alloc's init()
The problem is you’re trying to use instance methods on classes. Try these forms:
tell class "NSMutableDictionary" of current application to set pProperties to its dictionaryWithObjects_forKeys_(pValues, pKeys)
tell class "NSMutableArray" of current application to set pTransactions to its arrayWithCapacity_(10) -- number doesn't really matter
I’m not sure of the exact answer to that, but in most cases I’ve found that passing a list or record where an array or dictionary is required has worked fine.
Yes I started by adding the source files from the Cocoa Dev project into my ASOC project. Everything worked great with the bindings except we couldn’t figure out how to add something manually to the table. The call to the init methods in the OBJ-C class files wouldn’t work. Craig helped me set it up.
In the end Shane’s simple ASOC example worked and so I am going with that especially since it requires 6 fewer class files! If Shane’s idea hadn’t worked, the next step was to convert the Cocoa project to ASOC but without using bindings. Instead it was old “glue code.” I am still interested in seeing how one would set it up ASOC using the glue code, or the bindings method. Let me know if you succeed in doing that.
I have the project using the OBC-C files if you want it.
I am still working on the example with bindings (one last attempt) and still get the following error in the console.
02/10/2009 17:08:05 THAccounts[310] *** -[THAccount init]: The variable NSArray is not defined. (error -2753)
02/10/2009 17:08:05 THAccounts[310] Failed to create new object
Can anyone make sense of it in relation to the script below.
Thanks
Terry
script THAccount
property parent : class "NSObject"
property NSArray : class "NSArray"
property NSMutableDictionary : class "NSMutableDictionary"
property NSMutableArray : class "NSMutableArray"
property NSString : class "NSString"
property pProperties : missing value
property pTransactions : missing value
property pKeys : missing value
property pValues : missing value
on init()
continue init()
set pKeys to NSArray's arrayWithObjects_("title", missing value)
set pValues to NSArray's arrayWithObjects_("New Account", missing value)
set pProperties to NSMutableDictionary's dictionaryWithObjects_forKeys_(pValues, pKeys)
set pTransactions to NSMutableArray's arrayWithCapacity_(10)
return me
end init
on |properties|()
return pProperties
end |properties|
on setProperties_(newProperties)
if pProperties ≠newProperties then
set pProperties to NSMutableDictionary's dictionaryWithDictionary_(newProperties)
end if
end setProperties_
on transactions()
return pTransactions
end transactions
on setTransactions_(newTransactions)
if pTransactions ≠newTransactions then
set pTransactions to NSMutableDictionary's dictionaryWithDictionary_(newTransactions)
end if
end setTransactions_
end script
To refer to properties in your script, you need to say “my whatever”. And your class properties should be declared outside the script object – they need to refer to classes of the application, not classes of the script object.
Thanks again for the great translation of the two tables from the oBJ-C example. Are you going to work out the archiving too?
Also I was wondering if you tried it first with the datasource methods or just go for the bindings straight up?
I do like my version which is very simple and uses the applescript record but am having some issues with the images in the table. Also, I need drag and drop for the table and you need datasource methods for that. I may tinker with mine some more , or yours and see if I can use the datasource too for the needed methods. This may also solve the image thing.
In the Dev example you used, Scott Stevenson says you can mix and match bindings with data source methods. I have seen this online and others mention it - so here I go.