현재 현재 프로젝트에서 블록 복사본을 보려고합니다. 복사본의 구조는 NSIntegers, NSStrings 또 다른 NSMutableArray 및 두 개의 Object를 포함하는 NSMutableArray입니다. 이러한 객체는 차례대로 NSString을 보유합니다. 배열은 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
@Chuck에 동의해야합니다. 문제를 더 잘 설명해야합니다. 이제 우리가 알고있는 것은 copyWithZone : 메소드를 제공하려고한다는 것입니다. – TechZen