Created
February 13, 2018 15:08
-
-
Save DonMag/d13ce4dec6d95e7131d3afd6ecbb7647 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| class Foo { | |
| var test = "" | |
| } | |
| class Bar { | |
| var test = "" | |
| } | |
| var myArray = [AnyObject]() | |
| for i in 0..<5 { | |
| let f = Foo() | |
| f.test = "Foo \(i)" | |
| myArray.append(f) | |
| let b = Bar() | |
| b.test = "Bar \(i)" | |
| myArray.append(b) | |
| } | |
| print("myArray has", myArray.count, "elements") | |
| print(myArray) | |
| print() | |
| let fooArray = myArray.filter({ | |
| $0 is Foo | |
| }) | |
| let barArray = myArray.filter({ | |
| $0 is Bar | |
| }) | |
| print("fooArray has", fooArray.count, "elements") | |
| print(fooArray) | |
| print() | |
| print("barArray has", barArray.count, "elements") | |
| print(barArray) | |
| print() | |
| for f in fooArray { | |
| if let obj = f as? Foo { | |
| print(obj.test) | |
| } | |
| } | |
| print() | |
| for b in barArray { | |
| if let obj = b as? Bar { | |
| print(obj.test) | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment