We cannot avoid touching Cocoa framework to develop an app currently. But Swift has a very strong typing, which does not do well with the dynamic feature of Objective-C in fact. For example, we can use id to represent any type in Objective-C, while in Swift, AnyObject is hard to use and often has to be converted before use.

This kind of code is regular in Objective-C:

for (UIView *view in [self.view subviews]) {
    // Operation on view
    // If view is not a UIView in fact, crash
    // (But we know it won't happen)
    view.backgroundColor = [UIColor redColor];
}

There is no generic in Objective-C to ensure the type of collection. In Cocoa, the array returned by [self.view subviews] will always only contain UIView objects, but this information is not known by the compiler at all. Although the code above can run without problem, a safer version could be:

for (id object in [self.view subviews]) {
    if ([object isKindOfClass:[UIView class]]) {
        // Checked for object, it is UIView or its subclass
        UIView * view = (UIView *)object;
        // Operation on view
        // Since view is UIView, it is safe here
        view.backgroundColor = [UIColor redColor];
    }
}

Although there is generic in Swift, none of Cocoa APIs are using this feature. All ids in Objective-C are converted to AnyObject or AnyObject? (if it is possible to be nil). For collection type like array, except for some [String]s, most are [AnyObject]. Due to that, we can hardly use generic feature to work with Cocoa. There is an as! keyword to do explicit conversion in Swift. We can use is to do introspection with as!, the safe version of above in Swift is:

for object in self.view.subviews {
    if object is UIView {
        let view = object as! UIView
        view.backgroundColor = UIColor.redColor()
    }
}

That's quite a lot of code compared to the Objective-C version. However, if converting without checking, the app might crash when object is not our target type UIView. Swift optinal would be a help here, to make the code simpler. We can add a question mark after the as keyword. We will get a nil when the types do not match. This is a more Swift way to do it:

for object in self.view.subviews {
    if let view = object as? UIView {
        view.backgroundColor = UIColor.redColor()
    }
}

We can also change the whole [AnyObject] to [UIView], and then use it:

if let subviews = self.view.subviews as? [UIView] {
    for view in subviews {
        view.backgroundColor = UIColor.redColor()
    }
}

Note that converting the entire array and converting the element one by one is not the same. Array converting requires ALL elements in it are the target type. Otherwise, the result will be a nil instead of an array.

Of course, since Cocoa framework promises the elements in array from self.view.subviews are UIView. In this situation, it is no problem to change our code to explicit conversion:

for view in self.view.subviews as! [UIView] {
    view.backgroundColor = UIColor.redColor()
}

But remember, this is a simplify with cost, we lose safety here and should prepare for the risk.