Can you give more information on what you are trying to do? Is this just a single dictionary or an array of dictionaries that you are binding to a table, for instance.
But why do you want a dictionary with a nil value? I don’t know if you’re trying to do something like I did with a program to keep track of weather stats at my house. I add a date, low temp, high temp, rain amount, and a comment with the following statement:
But, of course there are a lot of days with no rain, so if newRain is missing value, then the key, rainAmount, just isn’t created for that dictionary and you have a blank cell in that column of the table, which is what I want. If I go back and edit that cell later, and put a number in there, then the dictionary is created.
I did think of this but in my case I want to read the dictionary and check whether there was rain on a particular day.
If the value/key does not exist how can I do that?
I suppose answering my own question, I check for the existence of the key, if the key does not exist then the value is “blank”.
The format I used was to check for the key, if it does not exist, create it with the value. Basically rdelmar’s solution. Thanks.
--If the key does not exist
--create a value for the key
if tThisRecDict's valueForKey_("myKey") = missing value then
tThisRecDict's setValue_forKey_(myValue, "myKey")
end if
IAC, NSNull’s |null|() is working as expected here:
set myDict to current application's NSMutableDictionary's dictionaryWithCapacity_(2)
tell myDict to setObject_forKey_("Blah", "Bar")
tell myDict to setObject_forKey_(current application's NSNull's |null|(), "Foo")
log myDict
set x to myDict's valueForKey_("Foo")
log x --> <null>
log x's |class|() --> NSNull
log x = current application's NSNull's |null|() --> 1
log Foo of (myDict as record) = missing value --> 1
The problem, perhaps, is that you were hoping for NSNull to be bridged to missing value, but it looks like you need to coerce its container to do that.