2

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?

kkiermasz
  • 464
  • 2
  • 15

2 Answers2

1

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

Graham Perks
  • 23,007
  • 8
  • 61
  • 83
1

Another Case

In my case, I get the same error when my "view" is optional property. I was adding the ".snp" part like in the accepted answer. But I get the same error.

Xcode Version 11.4 (11E146)

Solution

So I converted to the non-optional. Problem solved for my case.

I hope, it'll help someone else.

Best.

Community
  • 1
  • 1
MGY
  • 7,245
  • 5
  • 41
  • 74