Created
May 1, 2017 14:44
-
-
Save greggjaskiewicz/794962aacc957665defdf56b4d1f0be0 to your computer and use it in GitHub Desktop.
This file contains 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 | |
struct TypeOneStruct { | |
let foo1: Int | |
let foo2: Int | |
let bar1: Bool | |
} | |
struct TypeTwoStruct { | |
let fooString: String | |
let barBool: Bool | |
let foo1: Int | |
} | |
protocol FooBar { | |
func printFooBar() | |
} | |
final class TypeThreeObject:FooBar { | |
let foo: String | |
let bar: String | |
init(foo: String, bar: String) { | |
self.foo = foo | |
self.bar = bar | |
} | |
func printFooBar() { | |
print("\(self.bar) \(self.foo)") | |
} | |
} | |
enum OurStructs { | |
case one(TypeOneStruct) | |
case two(TypeTwoStruct) | |
case three(FooBar) | |
} | |
var cells: [OurStructs] = [] | |
func foo(row: Int) { | |
guard cells.count > row && row > 0 else { | |
print("index out of bounds") | |
return | |
} | |
let cellData = cells[row] | |
print(foo) | |
switch cellData { | |
case .one(let typeOne): | |
print("\(typeOne.bar1) \(typeOne.foo1) \(typeOne.foo2) ") | |
case .two(let typeTwo): | |
print("\(typeTwo.fooString) \(typeTwo.foo1) \(typeTwo.barBool) ") | |
case .three(let typeThree): | |
typeThree.printFooBar() | |
} | |
} | |
let a = TypeOneStruct(foo1: 1, foo2: 2, bar1: false) | |
let b = TypeOneStruct(foo1: 2, foo2: 3, bar1: true) | |
let c = TypeTwoStruct(fooString: "two", barBool: false, foo1: 2) | |
let d = TypeTwoStruct(fooString: "d", barBool: true, foo1: 5) | |
let f = TypeThreeObject(foo: "foo", bar: "bar") | |
cells.append(.one(b)) | |
cells.append(.two(c)) | |
cells.append(.one(a)) | |
cells.append(.two(d)) | |
cells.append(.three(f)) | |
foo(row: 1) | |
foo(row: 2) | |
foo(row: 3) | |
foo(row: 4) | |
foo(row: -5) | |
foo(row: 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment