user10121087
user10121087

Reputation:

Expression type '@lvalue CGRect' is ambiguous without more context

I'm trying to create something using swift playgrounds and am having some difficulty with the auto layout. Here is my code

import PlaygroundSupport
import UIKit

class ViewController: UIViewController {
    var gameVC = GameView()
    override func viewDidLoad() {
        super.viewDidLoad()
        gameVC.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(gameVC)
        gameVC.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
        gameVC.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
        gameVC.widthAnchor.constraint(equalToConstraint: view.frame.width).isActive = true
        gameVC.heightAnchor.constraint(equalToConstraint: view.frame.height).isActive = true
    }
}

I get errors on the line

gameVC.widthAnchor.constraint(equalToConstraint: view.frame.width).isActive = true

saying

Expression type '@lvalue CGRect' is ambiguous without more context

Thanks in advance!

Upvotes: 0

Views: 939

Answers (1)

Sulthan
Sulthan

Reputation: 130102

view.frame.width is not a constraint. You probably want

gameVC.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
gameVC.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true

or maybe:

gameVC.widthAnchor.constraint(equalToConstant: view.frame.width).isActive = true
gameVC.heightAnchor.constraint(equalToConstant: view.frame.height).isActive = true

I actually think there is no such method called constraint(equalToConstraint:).

Upvotes: 3

Related Questions