Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS: Object returning *nil description* after alloc and init
    text
    copied!<p>Let me preface this question by saying that I believe it to be a memory management mistake on my end. I just can't seem to figure out why it is happening.</p> <p>I have a viewcontroller and a model class named <code>Part</code>. </p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface Part : NSObject @property (nonatomic, strong) NSString *name; @property (nonatomic, strong) NSString *partType; @property (nonatomic, strong) NSString *description; @property (nonatomic, strong) NSNumber *price; - (id)initWithName:(NSString *)name AndType:(NSString *)type; @end </code></pre> <p>In the view controller I have a property set as follows:</p> <pre><code>@property (nonatomic, strong) Part *part; </code></pre> <p>In the <code>init</code> function of <code>ViewController</code> I create some static arrays and create objects out of them:</p> <pre><code>- (id)init { self = [super init]; self.partList = [[NSMutableArray alloc] init]; NSArray *inputArray = @[@"Part1", @"Part2", @"Part3", @"Part4", @"Part5", @"Part6", @"Part7", @"Part8"]; NSString *tempType = @"PartCategory"; // Add dummy static data for (int i = 0; i &lt; [inputArray count]; i++) { Part *partInput = [[Part alloc] initWithName:[inputArray objectAtIndex:i] AndType:tempType]; //partInput.name = [inputArray objectAtIndex:i]; //partInput.partType = tempType; NSLog(@"Inserting Part %@", partInput); [self.partList addObject:partInput]; } return self; } </code></pre> <p>The <code>NSLog</code> I call in that loop returns <code>Inserting Part *nil description*</code> for every part. I just can't track down what is happening here.</p> <p>EDIT: Here is the <code>initWithName</code> method from <code>Part</code> that the controller uses:</p> <pre><code>- (id)initWithName:(NSString *)name AndType:(NSString *)type { if(self = [super init]) { self.name = name; self.partType = type; } return self; } </code></pre>
 

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