如何將一個NSString複製到另一個NSString?將一個NSString複製到另一個
@interface MyData : NSObject
{
@private
//user's private info
NSInteger uID;
NSString *name;
NSString *surname;
NSString *email;
NSString *telephone;
//user's picture
UIImage *image;
}
@property (nonatomic, assign) int uID;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *surname;
@property (nonatomic, retain) NSString *email;
@property (nonatomic, retain) NSString *telephone;
@property (nonatomic, retain) UIImage *image;
@end
我有這種類型的兩個對象。 MyData * obj1,obj2;
首先被初始化。其次,我想先初始化。
obj2 = [obj1 copy]; //crashes
newData.surname = data.surname; //crashes to
newData.email = data.email;
newData.telephone = data.telephone;
我neeeeed的第二個對象不保留一個COPY!請幫助!感謝名單!
obj2實際上是一個MyData *?你需要MyData * obj1,* obj2; – Eiko 2010-11-17 15:45:33
是的。這種相同類型的變量! – yozhik 2010-11-17 15:48:25
MyData * obj1,* obj2;我只是忘記了asterix。 – yozhik 2010-11-17 15:49:00