Clone or Copy UIViewController or UIView

clone, copy, objective-c, uiview, uiviewcontroller

Solution

Use -

NSData *tempArchiveView = [NSKeyedArchiver archivedDataWithRootObject:self.view];
UIView *viewOfSelf = [NSKeyedUnarchiver unarchiveObjectWithData:tempArchiveView];

Similarly -

NSData *tempArchiveViewController = [NSKeyedArchiver archivedDataWithRootObject:self];
UIViewController *controller = [NSKeyedUnarchiver unarchiveObjectWithData:tempArchiveViewController];

Problem

UII need copy, self controller or self.view, i have tried: ``` UIView* viewOfSelf =[self.view copy]; UIViewController* controller = [self copy]; UIView* viewOfSelf =[self.view mutableCopy]; UIViewController* controller = [self mutableCopy]; ``` The error is: ``` -[UIViewController mutableCopyWithZone:]: unrecognized selector sent to instance 0xb803490 -[UIView copyWithZone:]: unrecognized selector sent to instance 0x6e0acb0 ```

Original source