Search code examples
swiftconstraintsnslayoutconstraintsnapkit

Xcode 10 beta SnapKit constraints type error


I'm using the Xcode 10 beta 5. My project is running on Swift 4 with the 4.0.0 SnapKit. I have a function which sets up UITableView's constraints:

private func setupConstraints() {
    tableView.snp.makeConstraints { make in
        make.leading.equalTo(view.safeAreaLayoutGuide.leadingAnchor)
        make.trailing.equalTo(view.safeAreaLayoutGuide.trailingAnchor)
        make.top.equalTo(view.safeAreaLayoutGuide.topAnchor)
        make.bottom.equalTo(view.safeAreaLayoutGuide.bottomAnchor)
    }
}

This function produces the following errors: Argument type 'NSLayoutXAxisAnchor' does not conform to expected type 'ConstraintRelatableTarget'

I tried view.safeAreaLayoutGuide.leadingAnchor as! ConstraintRelatableTarget, but this casting fails.

Do you guys have any idea how to fix it?


Solution

  • Try e.g. view.safeAreaLayoutGuide.snp.leading. You’re missing the .snp part and the final part differs too.