// 'as' for pattern matching
switch item {
case let obj as MyObject:
// this code will be executed if item is of type MyObject
case let other as SomethingElse:
// this code will be executed if item is of type SomethingElse
...
}
Bạn chỉ nên sử dụng as! nếu bạn chắc chắn 100% việc ép kiểu sẽ thành công (vì nếu bạn sai, toàn bộ chương trình sẽ bị hủy bỏ - abort).