Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Another thing to mention, you're having collisions with your getters/setters and their respective instance variables. So your implementation is:</p> <p><strong>interface</strong></p> <pre><code>@interface WSWCMPost : NSObject { NSString *postBody; // don't need to do these anymore for properties NSString *postTitle; NSString *postID; } @property (nonatomic, retain) NSString *postBody, *postTitle, *postID; </code></pre> <p><strong>implementation</strong></p> <pre><code>@implementation WSWCMPost @synthesize postBody, postTitle, postID; - (id)init { self = [super init]; if(self) { postID = @"none"; // not prefixing your variables with 'self' so they are not getting retained postBody = @"none"; postTitle = @"none"; } } </code></pre> <p>@end</p> <p>Here's how you should be writing those out:</p> <p><strong>interface</strong></p> <pre><code>/** NOTE: No need to specify your instance variables here anymore, just the properties */ @interface WSWCMPost : NSObject @property (nonatomic, retain) NSString *postID; @property (nonatomic, retain) NSString *postTitle; @property (nonatomic, retain) NSString *postBody; </code></pre> <p><strong>implementation</strong></p> <pre><code>@implementation WSWCMPost /** Now you specify the corresponding instance variable name alongside the property name */ @synthesize postBody=_postBody, postTitle=_postTitle, postID=_postID; - (id)init { self = [super init]; if(self) { self.postID = @"none"; //getting retained self.postBody = @"none"; self.postTitle = @"none"; } } </code></pre> <p>That would definitely cause data to be released too soon.</p> <p>So the previous way you could type in <strong>self.postID</strong> or <strong>postID</strong> and the compiler wouldn't complain. The difference is when you type <strong>postID</strong> it is actually setting the member variable and not retaining it... where <strong>self.postID</strong> will release whatever it is currently set to and retain the new value if it's different.</p> <p>By declaring your properties the new way, you have to either call the setter as <strong>self.postID</strong> or set the underlying instance variable as <strong>_postID</strong>. A lot of early iPhone books had you bang out properties that way and it just ends up causing all sorts of memory issues.</p> <p>Hope this helps!</p> <p><strong>UPDATE!!!</strong></p> <p>You forgot to return self in your constructor ;) I bet that's it</p> <pre><code>- (id)init { self = [super init]; if(self) { self.postID = @"none"; //getting retained self.postBody = @"none"; self.postTitle = @"none"; } return self; // THIS IS WHY, you're constructor doesn't return an instance of the class... add this please } - (id)initWithID: (NSString*)ID AndBody: (NSString*)body AndTitle: (NSString*)title { if(( self = [super init] )) { self.postTitle = title; self.postID = ID; self.postBody = body; } return self; } </code></pre>
    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.
    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