Swift xcode two errors: load controller is not allowed and autoresize not equal to views window <p>EDIT: If you need me to post more class programs just let me know in the comments.</p> <p>Screenshot of what I'm trying to create: <a href="http://i.stack.imgur.com/dmuFw.png" rel="nofollow">enter image description here</a></p> <p>NOTE: There's no need to look at the code below if you decide to run the project because all the classes I posted below are inside the dropbox zipped project file.</p> <p>Each of the squares on the bottom selects a different color and there's an invisible square that selects the type of shape off to the right of the green one. After the user selects one of these shapes, the user will be able to draw in a certain part of the screen.</p> <p>Entire project: <a href="https://www.dropbox.com/s/rhj641yku230f3v/SwiftXcodeProejctTwoErrors6767.zip?dl=0" rel="nofollow">https://www.dropbox.com/s/rhj641yku230f3v/SwiftXcodeProejctTwoErrors6767.zip?dl=0</a></p> <p>If you run the project, create an account, then click sign in, then click one of the rows, then click on one of the colored boxes (red and green squares) the app will crash and get the following error message:</p> <pre><code>2016-03-11 17:06:43.580 finalProject2[11487:1058358] &lt;UIView: 0x7faba1677710; frame = (0 0; 414 736); autoresize = W+H; gestureRecognizers = &lt;NSArray: 0x7faba1658d90&gt;; layer = &lt;CALayer: 0x7faba16563f0&gt;&gt;'s window is not equal to &lt;finalProject2.RowTableViewController: 0x7faba165a3c0&gt;'s view's window! File slot 1 File slot 2 File slot 3 File slot 4 File slot 5 File slot 6 File slot 7 File slot 8 File slot 9 File slot 10 File slot 11 File slot 12 2016-03-11 17:06:44.746 finalProject2[11487:1058358] Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (&lt;UIAlertController: 0x7faba16b7d60&gt;) </code></pre> <p>MainProject scene class:</p> <pre><code>import UIKit weak var FirstFileNameTextField: UILabel! enum ShapeType: String { case Line = "Line" case Ellipse = "Ellipse" case Rectangle = "Rectangle" case FilledEllipse = "Filled Ellipse" case FilledRectangle = "Filled Rectangle" case Scribble = "Scribble" } let shapes: [ShapeType] = [ .Line, .Ellipse, .Rectangle, .FilledEllipse, .FilledRectangle, .Scribble ] class MainProjectScene: UIViewController { var row: Row? @IBAction func PressedSaveAs(sender: UIButton) //this is the save as function that I would like to know how to change { //1. Create the alert controller. var alert = UIAlertController(title: "Name/rename your file:", message: "Enter a filename to name/rename and save your file", preferredStyle: .Alert) //2. Add the text field. You can configure it however you need. alert.addTextFieldWithConfigurationHandler({ (textField) -&gt; Void in textField.text = "Your file name" }) alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (action) -&gt; Void in let textField = alert.textFields![0] as UITextField print("Text field: \(textField.text)") // rows.cell.textLabel?.text = textField.text CurrentFileName = textField.text! rows[IndexPath.row].FileName = textField.text! rows[IndexPath.row].UserText = self.TextUserScrollEdit.text! })) // 4. Present the alert. self.presentViewController(alert, animated: true, completion: nil) // rows[indexPath.row].FileName = rows.cell.textLabel?.text // rows[i] = textField.text // if let detailViewController = segue.destinationViewController as? MainProjectScene { // if let cell = sender as? UITableViewCell { // if let indexPath = self.tableView.indexPathForCell(cell) { // detailViewController.row = rows[indexPath.row] } override func viewWillAppear(animated: Bool) { if let r = row { row!.FileName = r.FileName row!.QuartzImage = r.QuartzImage row!.UserText = r.UserText rows[IndexPath.row].UserText = self.TextUserScrollEdit.text! } } override func viewDidLoad() { super.viewDidLoad() TextUserScrollEdit.text = rows[IndexPath.row].UserText // FacebookButton.addTarget(self, action: "didTapFacebook", forControlEvents: .TouchUpInside) } @IBOutlet weak var TextUserScrollEdit: UITextView! @IBOutlet weak var NewFileButton: UIButton! @IBOutlet weak var TwoDQuartzButton: UIButton! @IBOutlet weak var YouTubeButton: UIButton! @IBOutlet weak var TwitterButton: UIButton! @IBOutlet weak var OpenFileButton: UIButton! @IBOutlet weak var SnapChatButton: UIButton! @IBOutlet weak var FacebookButton: UIButton! @IBAction func PressedTwoDQuartzButton(sender: UIButton) { } @IBAction func PressedSnapchatButton(sender: UIButton){ UIApplication.sharedApplication().openURL(NSURL(string: "https://www.snapchat.com/")!) } @IBAction func PressedYouTubeButton(sender: UIButton) { UIApplication.sharedApplication().openURL(NSURL(string: "https://www.youtube.com/")!) } @IBOutlet weak var InstagramButton: UIButton! @IBAction func PressedFacebookButton(sender: UIButton) { UIApplication.sharedApplication().openURL(NSURL(string: "http://www.facebook.com")!) } @IBAction func PressedInstagramButton(sender: UIButton) { UIApplication.sharedApplication().openURL(NSURL(string: "https://www.instagram.com/")!) } @IBAction func PressedTwitterButton(sender: UIButton) { UIApplication.sharedApplication().openURL(NSURL(string: "https://twitter.com/")!) } @IBOutlet weak var SaveAsButton: UIButton! // @IBOutlet weak var shapeButton: ShapeButton! @IBOutlet weak var canvas: CanvasView! @IBOutlet var colorButtons: [UIButton]! @IBOutlet weak var shapeButton: ShapeButton! @IBAction func selectColor(sender: UIButton) { UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: CGFloat(0.25), initialSpringVelocity: CGFloat(0.25), options: UIViewAnimationOptions.CurveEaseInOut, animations: { for button in self.colorButtons { button.frame.origin.y = self.view.bounds.height - 58 } sender.frame.origin.y -= 20 }, completion: nil) canvas.color = sender.backgroundColor! shapeButton.color = sender.backgroundColor! } @IBAction func selectShape(sender: ShapeButton) { let title = "Select Shape" let alertController = UIAlertController(title: title, message: nil, preferredStyle: .ActionSheet) for shape in shapes { let action = UIAlertAction(title: shape.rawValue, style: .Default) { action in sender.shape = shape self.canvas.shape = shape } alertController.addAction(action) } presentViewController(alertController, animated: true, completion: nil) } } </code></pre> <p>ShapeButton class:</p> <pre><code>import UIKit class ShapeButton: UIButton { let shapes: [ShapeType] = [ .Line, .Ellipse, .Rectangle, .FilledEllipse, .FilledRectangle, .Scribble ] var shape: ShapeType = .Line { didSet { setNeedsDisplay() } } var color: UIColor = UIColor.blueColor() { didSet { setNeedsDisplay() } } // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. override func drawRect(rect: CGRect) { // Drawing code let context = UIGraphicsGetCurrentContext() CGContextSetStrokeColorWithColor(context, color.CGColor) CGContextSetFillColorWithColor(context, color.CGColor) CGContextSetLineWidth(context, 2) let x1: CGFloat = 5 let y1: CGFloat = 5 let x2: CGFloat = frame.width - 5 let y2: CGFloat = frame.height - 5 let rect = CGRect(x: x1, y: y1 + 5, width: frame.width - 10, height: frame.height - 20) switch shape { case .Line: CGContextMoveToPoint(context, x1, y1) CGContextAddLineToPoint(context, x2, y2) CGContextStrokePath(context) case .Ellipse: CGContextStrokeEllipseInRect(context, rect) case .Rectangle: CGContextStrokeRect(context, rect) case .FilledEllipse: CGContextFillEllipseInRect(context, rect) case .FilledRectangle: CGContextFillRect(context, rect) case .Scribble: CGContextMoveToPoint(context, x1, y1) CGContextAddCurveToPoint(context, x1 + 80, y1 - 10, // the 1st control point x2 - 80, y2 + 10, // the 2nd control point x2, y2) // the end point CGContextStrokePath(context) } } } </code></pre> <p>Canvas view class:</p> <pre><code>import UIKit /* This program is for Xcode 6.3 and Swift 1.2 */ class CanvasView: UIView { var shape: ShapeType = .Line var color: UIColor = UIColor.blueColor() var first :CGPoint = CGPointZero var last :CGPoint = CGPointZero var points: [CGPoint] = [] // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. override func drawRect(rect: CGRect) { // Drawing code let context = UIGraphicsGetCurrentContext() CGContextSetStrokeColorWithColor(context, color.CGColor) CGContextSetFillColorWithColor(context, color.CGColor) let rect = CGRect(x: first.x, y: first.y, width: last.x - first.x, height: last.y - first.y) switch shape { case .Line: CGContextMoveToPoint(context, first.x, first.y) CGContextAddLineToPoint(context, last.x, last.y) CGContextStrokePath(context) case .Ellipse: CGContextStrokeEllipseInRect(context, rect) case .Rectangle: CGContextStrokeRect(context, rect) case .FilledEllipse: CGContextFillEllipseInRect(context, rect) case .FilledRectangle: CGContextFillRect(context, rect) case .Scribble: CGContextMoveToPoint(context, first.x, first.y) for p in points { CGContextAddLineToPoint(context, p.x, p.y) } CGContextStrokePath(context) } } override func touchesBegan(touches: Set&lt;UITouch&gt;, withEvent event: UIEvent?) { if let touch = touches.first { first = touch.locationInView(self) last = first points.removeAll(keepCapacity: true) if shape == .Scribble { points.append(first) } setNeedsDisplay() } } override func touchesMoved(touches: Set&lt;UITouch&gt;, withEvent event: UIEvent?) { if let touch = touches.first { last = touch.locationInView(self) if shape == .Scribble { points.append(last) } setNeedsDisplay() } } override func touchesEnded(touches: Set&lt;UITouch&gt;, withEvent event: UIEvent?) { if let touch = touches.first { last = touch.locationInView(self) if shape == .Scribble { points.append(last) } setNeedsDisplay() } } override func touchesCancelled(touches: Set&lt;UITouch&gt;?, withEvent event: UIEvent?) { } } </code></pre>