Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS – NSMutableArray and Block Copy
    primarykey
    data
    text
    <p>Currently I’m trying to get the hang of a block copy with my current project. The structure of the copy is an NSMutableArray that contains NSIntegers, NSStrings another NSMutableArray and two Objects… Those objects in turn hold NSStrings. The Array contains Objects which hold an NSInteger and Two Objects which contain strings…</p> <p>I believe I am supposed to use the Block Copy method for coping objects… Code is below…</p> <p>I am aware the code is not releasing properly… I tried to make the code smaller for your benefit.</p> <p>Any insight you could shed would be awesome.</p> <pre><code>//Main controller Excerpt //Insert Position Information into temporary node point... Node Points can have multiple Positions (or rather you can face multiple directions at the node. Each Node has 3-4 of these. [newNode.positionArray insertObject:[newPosition copy] atIndex:currentPosition]; Insert the temporary node into the Node Array. [nodeArray insertObject:[newNode copy] atIndex:count]; //Main Controller Excerpt // // Node.h // #import &lt;Foundation/Foundation.h&gt; @class Sequence; @class Position; @interface Node : NSObject { NSInteger Id; NSInteger currentPosition; NSString *title; NSMutableArray *positionArray; Sequence *forwardSequence; Sequence *backSequence; } -(id) copyWithZone: (NSZone *) zone; @property (nonatomic, assign) NSInteger Id; @property (nonatomic, assign) NSInteger currentPosition; @property (nonatomic, assign) NSString *title; @property (nonatomic, retain) NSMutableArray *positionArray; @property (nonatomic, retain) Sequence *forwardSequence; @property (nonatomic, retain) Sequence *backSequence; @end // // Node.m // #import "Sequence.h" #import "Position.h" #import "Node.h" @implementation Node @synthesize Id; @synthesize currentPosition; @synthesize positionArray; @synthesize title; @synthesize forwardSequence; @synthesize backSequence; -(id) copyWithZone: (NSZone *) zone { Node *nodeCopy = [[Node allocWithZone: zone] init]; nodeCopy.Id = Id; nodeCopy.currentPosition = currentPosition; nodeCopy.positionArray = [positionArray copy]; nodeCopy.title = title; nodeCopy.forwardSequence = [forwardSequence copy]; nodeCopy.backSequence = [backSequence copy]; return nodeCopy; } @end // // Position.h // #import &lt;Foundation/Foundation.h&gt; @class Sequence; @interface Position : NSObject &lt;NSCopying&gt; { NSInteger Id; Sequence *leftSequence; Sequence *rightSequence; } @property (nonatomic, assign) NSInteger Id; @property (nonatomic, retain) Sequence *leftSequence; @property (nonatomic, retain) Sequence *rightSequence; -(id) copyWithZone: (NSZone *) zone; @end // // Position.m // #import "Sequence.h" #import "Position.h" @implementation Position @synthesize Id; @synthesize leftSequence; @synthesize rightSequence; -(id) copyWithZone: (NSZone *) zone { Position *positionCopy = [[Position allocWithZone: zone] init]; positionCopy.Id = Id; positionCopy.leftSequence = [leftSequence copy]; positionCopy.rightSequence = [rightSequence copy]; return positionCopy; } @end // // Sequence.h // #import &lt;Foundation/Foundation.h&gt; @interface Sequence : NSObject &lt;NSCopying&gt; { NSInteger numberOfFrames; NSString *imageNameScheme; NSString *endFrame; } -(id) copyWithZone: (NSZone *) zone; @property (nonatomic, assign) NSInteger numberOfFrames; @property (nonatomic, copy) NSString *imageNameScheme; @property (nonatomic, copy) NSString *endFrame; @end // // Sequence.m // MCIT // #import "Sequence.h" @implementation Sequence @synthesize numberOfFrames; @synthesize imageNameScheme; @synthesize endFrame; -(id) copyWithZone: (NSZone *) zone { Sequence *sequenceCopy = [[Sequence allocWithZone: zone] init]; sequenceCopy.numberOfFrames = numberOfFrames; sequenceCopy.imageNameScheme = imageNameScheme; sequenceCopy.endFrame = endFrame; return sequenceCopy; } @end </code></pre> <p>Works like a charm now thanks all. :D</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.
    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