I just try to update some of my apps and make use of the Cocoa
bindings, which really works nice. As I mentioned in another thread,
it means I have to take care of the User Defaults.
This finally means could planning of the app's structure and often
quite a lot of code typing, which includes some kind of potential
typing errors.
So I decided to build a small basic app for that , which generates
the AS code for me, like the example workflow described below.
In IB create a new binding like a boolean for a check box, copy the
name and tell the app to create a new boolean variable with the
contents of the clipboard as name, and so on. At the end you got a
list of variables and their contents in the app. For each variable
you can decide whether it should be read and/or whether it should be
added to the properties. Then click the create code button and the
app will generate the code and put it to the clipboard like:
on will finish launching theObject
my setUserDefaults(defaultList)
set {textValue1, textValue2, convertTimes, formatXML,
styleFormats} to my readUserDefaults()
end will finish launching
on setUserDefaults(defaultList)
repeat with theEntry in defaultList
try
make new default entry at end of default entries of user
defaults with properties {name:item 1 of theEntry, contents:item 2 of
theEntry}
on error theError
log {"error @ creating user defaults", (item 1 of
theEntry) as text, (item 2 of theEntry) as text, theError}
end try
end repeat
tell user defaults to register
end setUserDefaults
on readUserDefaults()
set readList to {"textValue1", "textValue2", "convertTimes",
"formatXML", "styleFormats"}
set varList to {}
repeat with theEntry in readList
try
tell user defaults
set end of varList to content of default entry theEntry
end tell
on error theError
log {"error @ reading user defaults", theEntry, theError}
end try
end repeat
return varList
end readUserDefaults
If somebody has a use for that let me know, I can upload the app and
the source to my website.