Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 29, 2006, 11:10 AM   #1
gekko513
macrumors 601
 
gekko513's Avatar
 
Join Date: Oct 2003
Program Design and documentation using Key-Value coding

I don't know any coding practices, model designs and documentation standards that address Key-Value coding properly, but maybe there is and I've missed it.

Standard UML lists members and methods but how do you handle the planning of possible keys for members that are dictionaries of key-value pairs?

.h files with method prototypes makes documenting the purpose and the way to use a class easy, with the exception of key-value based methods. Is there a recommended way and place to document the key-value behaviour of a class in the .h file?

Is there a best practice standard for documenting key-value properties when used with cocoa bindings?
__________________
Someone get Nekkid™, now!
gekko513 is offline   0 Reply With Quote
Old Apr 29, 2006, 01:54 PM   #2
caveman_uk
Guest
 
caveman_uk's Avatar
 
Join Date: Feb 2003
Location: Hitchin, Herts, UK
I presume you mean aside from the setter/getter methods a class may have?
caveman_uk is offline   0 Reply With Quote
Old Apr 29, 2006, 02:02 PM   #3
gekko513
Thread Starter
macrumors 601
 
gekko513's Avatar
 
Join Date: Oct 2003
Yes, I mean if a class has a member for instance like this:

- (NSMutableDictionary*) properties;
- (void) setProperties:(NSMutableDictionary*)p;
__________________
Someone get Nekkid™, now!
gekko513 is offline   0 Reply With Quote
Old Apr 29, 2006, 03:52 PM   #4
HiRez
macrumors 68040
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
I don't think so. AFAIK the convention of stuffing a class's properties into a dictionary is not an Apple/NeXT one. I can't recall seeing it done that way in any official Apple code, I think they prefer the separate setter/getter methods.
__________________
Go outside, the graphics are amazing!
HiRez is online now   0 Reply With Quote
Old Apr 29, 2006, 04:02 PM   #5
gekko513
Thread Starter
macrumors 601
 
gekko513's Avatar
 
Join Date: Oct 2003
Quote:
Originally Posted by HiRez
I don't think so. AFAIK the convention of stuffing a class's properties into a dictionary is not an Apple/NeXT one. I can't recall seeing it done that way in any official Apple code, I think they prefer the separate setter/getter methods.
Then what's NSUserDefaults?
__________________
Someone get Nekkid™, now!
gekko513 is offline   0 Reply With Quote
Old Apr 29, 2006, 04:49 PM   #6
caveman_uk
Guest
 
caveman_uk's Avatar
 
Join Date: Feb 2003
Location: Hitchin, Herts, UK
...or indeed the print system which relies on a dictionary (NSPrintInfo).

In short, to answer your question....I dunno. If you find an answer let me know (other than commenting a like hell in the .h file).

Other tricky questions...how do you document a .nib with a ton of bindings in it?
caveman_uk is offline   0 Reply With Quote
Old Apr 29, 2006, 04:53 PM   #7
gekko513
Thread Starter
macrumors 601
 
gekko513's Avatar
 
Join Date: Oct 2003
Quote:
Originally Posted by caveman_uk
Other tricky questions...how do you document a .nib with a ton of bindings in it?
Exactly ...

We didn't learn about these kinds of things in CS. That's why I'm asking.

Do the Cocoa programming books have anything to say about this? Have anyone here read them?
__________________
Someone get Nekkid™, now!
gekko513 is offline   0 Reply With Quote
Old Apr 29, 2006, 05:06 PM   #8
caveman_uk
Guest
 
caveman_uk's Avatar
 
Join Date: Feb 2003
Location: Hitchin, Herts, UK
Quote:
Originally Posted by gekko513
Do the Cocoa programming books have anything to say about this? Have anyone here read them?
I've read them and the answer is no.
caveman_uk is offline   0 Reply With Quote
Old Apr 30, 2006, 11:26 PM   #9
HiRez
macrumors 68040
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
Quote:
Originally Posted by gekko513
Then what's NSUserDefaults?
NSUserDefaults and similar items are special cases, I'm talking about generic object property accessors. And I've never seen Apple do them with a dictionary, though I've seen it in a bunch of third-party code.
__________________
Go outside, the graphics are amazing!
HiRez is online now   0 Reply With Quote
Old May 1, 2006, 12:35 AM   #10
gekko513
Thread Starter
macrumors 601
 
gekko513's Avatar
 
Join Date: Oct 2003
Quote:
Originally Posted by HiRez
NSUserDefaults and similar items are special cases, I'm talking about generic object property accessors. And I've never seen Apple do them with a dictionary, though I've seen it in a bunch of third-party code.
Apple uses NSDictionary for class attributes in NSOpenGLPixelFormat and NSAttributedString also.

I can't remember having seen Apple using mutable property dictionaries, though.

But there's a Cocoa Bindings tutorial over at CocoaDevCentral that can give some explaination why you see it in a bunch of third-party code.

That's the place I got the idea of using property dictionaries with cocoa bindings. It's very convenient, but I see some documentation and maintainability problems with the practice.
__________________
Someone get Nekkid™, now!
gekko513 is offline   0 Reply With Quote
Old May 1, 2006, 12:45 PM   #11
Palad1
macrumors 6502a
 
Palad1's Avatar
 
Join Date: Feb 2004
Location: London, UK
Here's my coding practices when I'm using hashtables (c++ / c / c#):

If the number and content of the keys can be known at compile time, I usually stuff them in the class containing the hashtable.

If the number cannot be known, but the format is, I create a method that outputs a key. Here's a c# sample:

PHP Code:
public class MyClass
{
 private 
m_Hash=new Dictionary<string,string>();

 
/// <summary>
 /// Outputs a key for the dictionary 'id:epoch"
 /// <summary>
 
public static string KeyForDictionary(int idDateTime time){
   return 
string.Format("{0}:{1}",id,time.Ticks);
 }
///... lotsa code but I gotta go

cheers
Palad1 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Core Data and Key-Value Coding gormster Mac Programming 2 Jan 31, 2010 07:12 AM
Can someone make me and app using the code? bob5731 Wasteland 3 Aug 5, 2009 08:39 PM
Key-Value Coding ....a perspective please mdeh Mac Programming 4 Mar 24, 2009 10:33 PM
Key-Value Coding and Encapsulation MacRohde Mac Programming 5 Jun 26, 2007 06:48 PM
Key-Value Coding Question Soulstorm Mac Programming 4 Feb 13, 2007 05:53 PM


All times are GMT -5. The time now is 12:13 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC