You can’t call arbitrary functions on AnyObject anymore. Previously, you could 
do this:

let a: AnyObject = UIView()
a.hasPrefix(“test”) // This compiled (because hasPrefix(:_) exists on 
NSString), but would obviously crash

This is not allowed anymore.

> On 25 Aug 2016, at 03:33, Travis Griggs via swift-users 
> <swift-users@swift.org> wrote:
> 
> Upgrading to beta6 of Xcode8, I’ve read through various SE’s and made fixes 
> as appropriate, but the following behavior I didn’t catch an explanation as 
> to why its now an error where it was fine before.
> 
> In a ViewController, I have something that looks like:
> 
>    var addButton = UIButton(type: .custom)
>    var addPrompt = UILabel()
>    var timesButton = UIButton(type: .system)
>    var removeButton = UIButton(type: .system)
>    var menuButton = UIButton(type: .system)
>       
>    func commonInit() {
>        [self.addButton, self.addPrompt, self.timesButton, self.removeButton, 
> self.menuButton].forEach { control in
>            control.sizeToFit()
>            self.addSubview(control)
>    }
> 
> This code was fine until the latest update. It seemed to a heterogenous array 
> of UILabel and UIButtons was a homogeneous array of UIView objects. But now I 
> get the errors:
> 
>    Value of type ‘Any’ has no member ‘sizeToFit'
>    Cannot covert value of type ‘Any’ to expected argument type of ‘UIView’
> 
> This seems like it might be related to SE-0116 (Import Objective-C id as 
> Swift Any ) but I’m not sure why the inferencer can no longer find the shared 
> parent type, where it could before.
> 
> Aside, I can fix it by simply helping it a little, e.g.
> 
>    [self.addButton, self.addPrompt, self.timesButton, self.removeButton, 
> self.menuButton].forEach { (control:UIView) in...
> 
> But remain curious why the inferencer can’t handle this for me anymore.
> 
> 
> 
> _______________________________________________
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to