Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@available with pre-available iOS versions - missing properties

Tags:

ios

ios9

swift

I've implemented such class:

class MapLayoutGuide: NSObject, UILayoutSupport {
    var insetLength: CGFloat = 0
    init(insetLength: CGFloat) {
        self.insetLength = insetLength
    }
    var length: CGFloat {
        return insetLength
    }
}

Everything was working fine, however there were new changes introduced with new iOS version: Apple changelog.

So now I'm receiving 3 errors:

  • Protocol requires property 'topAnchor' with type 'NSLayoutYAxisAnchor',
  • Protocol requires property 'bottomAnchor' with type 'NSLayoutYAxisAnchor',
  • Protocol requires property 'heightAnchor' with type 'NSLayoutDimension'.

Looking into UILayoutSupport implementation I can see new variables:

@available(iOS 9.0, *)
var topAnchor: NSLayoutYAxisAnchor { get }
@available(iOS 9.0, *)
var bottomAnchor: NSLayoutYAxisAnchor { get }
@available(iOS 9.0, *)
var heightAnchor: NSLayoutDimension { get }

My app is iOS 8.0+. So the question is what should I do with these values..? I can't set @available flag and I want the code to work both with iOS 8 and 9, but I have to override it. No conception what to do with it.

The code used to work yesterday on Xcode Beta 1, what ofc doesn't matter atm as I want it to work on current API not previous.

like image 769
Nat Avatar asked Jun 30 '15 13:06

Nat


1 Answers

It worked after cleaning the project.

@available(iOS 9.0, *)
var topAnchor: NSLayoutYAxisAnchor {
    return NSLayoutYAxisAnchor()
}


@available(iOS 9.0, *)
var bottomAnchor: NSLayoutYAxisAnchor {
    return NSLayoutYAxisAnchor()
}


@available(iOS 9.0, *)
var heightAnchor: NSLayoutDimension {
    return NSLayoutDimension()
}
like image 55
Nat Avatar answered Sep 22 '22 12:09

Nat