目前我正试图获得当前项目的块副本的挂起。该副本的结构是一个NSMutableArray,它包含NSIntegers,NSStrings另一个NSMutableArray和两个对象...这些对象又保存NSStrings。该数组包含持有一个NSInteger和包含字符串的两个对象...iOS - NSMutableArray和块复制
我相信我应该使用的块复制方法进行应对对象的对象...代码如下...
我知道代码没有释放妥善......我试着让代码变得更小以利于您的利益。
任何你可以摆脱的见解都会很棒。
//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 <Foundation/Foundation.h>
@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 <Foundation/Foundation.h>
@class Sequence;
@interface Position : NSObject <NSCopying> {
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 <Foundation/Foundation.h>
@interface Sequence : NSObject <NSCopying> {
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
现在感谢所有工作。 :d
我不确定我理解你的问题。 1)在这种情况下,“块复制”是什么意思?它看起来像一个正常的复制方法。 2)关于你发布的代码,你在问什么?你有问题吗? – Chuck 2011-03-01 21:29:15
我被迫同意@Chuck。你需要更好地解释你的问题。我们现在知道的是,您正在尝试提供copyWithZone:方法。 – TechZen 2011-03-01 21:37:12