Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

OT: User Defaults and Cocoa bindings



Hi,

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:

property defaultList : {{"textValue1", "ABC"}, {"textValue2", "DEF"}, {"convertTimes", true}, {"formatXML", true}, {"styleFormats", {"Bold", "Italic", "Bold/Italic"}}}

property textValue1 : "ABC"
property textValue2 : "DEF"
property convertTimes : true
property formatXML : true
property styleFormats :  {"Bold", "Italic", "Bold/Italic"}

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.

Regards
Andreas


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-studio mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.