Last active
August 29, 2015 14:12
-
-
Save coryalder/b5405b9abac79013c791 to your computer and use it in GitHub Desktop.
Solving Protocol issue using an abstract class
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
// Playground - noun: a place where people can play | |
import UIKit | |
class MyItem { /* some model properties */ } | |
protocol ItemViewProtocol: class { | |
// some protocol methods (e.g. updateWithItem(), etc) | |
func setupItem(item: MyItem) | |
init(String) | |
} | |
class ItemView: UIView, ItemViewProtocol { | |
required init(_: String) { | |
super.init() | |
} | |
required init(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
func setupItem(item: MyItem) { | |
} | |
} | |
class SpecificItemView: ItemView { | |
override func setupItem(item: MyItem) { | |
// do item setup | |
} | |
} | |
class AnotherItemView: ItemView { | |
override func setupItem(item: MyItem) { | |
// do DIFFERENT item setup | |
} | |
} | |
class MyViewController: UIViewController { | |
var itemView: ItemView = SpecificItemView("ok") as ItemView | |
override func viewDidLoad() { | |
itemView.setupItem(MyItem()) | |
itemView.removeFromSuperview() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment