Search code examples
iosswiftuiviewframenskeyedarchiver

Cannot change the frame properties of a UIView


I have a UIView

@IBOutlet weak var myView: UIView!

I copy it using NSArchiver

var topview = NSKeyedUnarchiver.unarchiveObjectWithData(NSKeyedArchiver.archivedDataWithRootObject(self.myView));

I attempt to alter it using CGRectMake

topview?.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height * 1.5)

In response to the line above's '=' I receive the error

Cannot assign to result of this expression

I have attempted a variety of ways to alter topview's frame properties though each try is eventually met with this error. Any help would be greatly appreciated.


Solution

  • unarchiveObjectWithData returns an optional AnyObject and AnyObject itself does not have frame property. So you need to cast topView to UIView

    var topview = NSKeyedUnarchiver.unarchiveObjectWithData(NSKeyedArchiver.archivedDataWithRootObject(self.myView)) as? UIView