Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this a good (Cocoa-like, Apple-approved) model class?
    primarykey
    data
    text
    <p>I've been using Objective-C for a while, but I've not been following Apple's guidelines very well. Recently I read <a href="http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/CocoaFundamentals/CocoaDesignPatterns/CocoaDesignPatterns.html" rel="nofollow noreferrer" title="Cocoa Design Patterns">Cocoa Design Patterns</a> and the <a href="http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/ModelObjects/Introduction.html" rel="nofollow noreferrer" title="Model Object Implementation Guide">Model Object Implementation Guide</a>, and I'm trying to do some very simple things, but do them very well.</p> <p>Have I missed any major concepts? Please don't mention <code>self = [super init]</code>; that's been covered many times on SO already. Feel free to critique my <code>#pragma mark</code>s though!</p> <pre><code>#import "IRTileset.h" #import "IRTileTemplate.h" @interface IRTileset () //No longer lists protocols because of Felixyz @property (retain) NSMutableArray* tileTemplates; //Added because of TechZen @end #pragma mark - @implementation IRTileset #pragma mark - #pragma mark Initialization - (IRTileset*)init { if (![super init]) { return nil; } tileTemplates = [NSMutableArray new]; return self; } - (void)dealloc { [tileTemplates release]; [uniqueID release]; //Added because of Felixyz (and because OOPS. Gosh.) [super dealloc]; //Moved from beginning to end because of Abizern } #pragma mark - #pragma mark Copying/Archiving - (IRTileset*)copyWithZone:(NSZone*)zone { IRTileset* copy = [IRTileset new]; [copy setTileTemplates:tileTemplates]; //No longer insertTileTemplates: because of Peter Hosey [copy setUniqueID:uniqueID]; return copy; //No longer [copy autorelease] because of Jared P } - (void)encodeWithCoder:(NSCoder*)encoder { [encoder encodeObject:uniqueID forKey:@"uniqueID"]; [encoder encodeObject:tileTemplates forKey:@"tileTemplates"]; } - (IRTileset*)initWithCoder:(NSCoder*)decoder { [self init]; [self setUniqueID:[decoder decodeObjectForKey:@"uniqueID"]]; [self setTileTemplates:[decoder decodeObjectForKey:@"tileTemplates"]]; //No longer insertTileTemplates: because of Peter Hosey return self; } #pragma mark - #pragma mark Public Accessors @synthesize uniqueID; @synthesize tileTemplates; - (NSUInteger)countOfTileTemplates { return [tileTemplates count]; } - (void)insertTileTemplates:(NSArray*)someTileTemplates atIndexes:(NSIndexSet*)indexes { [tileTemplates insertObjects:someTileTemplates atIndexes:indexes]; } - (void)removeTileTemplatesAtIndexes:(NSIndexSet*)indexes { [tileTemplates removeObjectsAtIndexes:indexes]; } //These are for later. #pragma mark - #pragma mark Private Accessors #pragma mark - #pragma mark Other @end </code></pre> <p>(Edit: I've made the changes suggested so far and commented which answers discuss them, in case anyone needs to know why.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload