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
class Person { | |
var name: String | |
var surname: String | |
init(name: String, surname: String) { | |
self.name = name | |
self.surname = surname | |
} | |
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
//Init is automatically created | |
struct Person { | |
var name: String | |
var surname: String | |
} | |
let person = Person(name: "Dante", surname: "Brazeal") | |
//Assign person to another variable. | |
var secondPerson = person | |
//Change name of second person |
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
// Define protocol | |
protocol SimpleViewCellItem {} | |
// Let all types, which you want to show in table view, comforms to that protocol | |
struct Person: SimpleViewCellItem { | |
var name: String | |
var surname: String | |
} |
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
public final class SimpleViewController: UIViewController { | |
@IBOutlet weak var tableView: UITableView! | |
// List of items, showed in TableView | |
var peopleWithAdvertisementList: [SimpleViewCellItem]! | |
public override func viewDidLoad() { | |
setupTableView() | |
createDummyList() |
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
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
var dequeuedCell: UITableViewCell? | |
if peopleWithAdvertisementList[indexPath.row] is Advertisement { | |
dequeuedCell = tableView.dequeueReusableCell(withIdentifier: "AdvertisementCell") | |
} else if peopleWithAdvertisementList[indexPath.row] is Person { | |
dequeuedCell = tableView.dequeueReusableCell(withIdentifier: "PeopleCell") | |
} else { | |
// Else what? Do we have other type comforming to SimpleViewCellItem protocol? | |
} |
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
extension SimpleViewController { | |
enum CellType { | |
case advertisement(Advertisement) | |
case person(Person) | |
} | |
} |
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
// Right now you can delete SimpleViewCellType protocol | |
struct Person { | |
var name: String | |
var surname: String | |
} | |
struct Advertisement { | |
var brandName: String | |
} |
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
class ViewController: UIViewController { | |
@IBOutlet weak var userImageView: UIImageView! | |
@IBOutlet weak var messageButton: UIButton! | |
@IBOutlet weak var followButton: UIButton! | |
@IBOutlet weak var userNameLabel: UILabel! | |
@IBOutlet weak var phoneNameButton: UIButton! | |
@IBOutlet weak var phoneNameLabel: UILabel! | |
@IBOutlet weak var phoneNameRightImageView: UIImageView! |
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
struct User { | |
let name: String | |
let surname: String | |
let photo: UIImage | |
} | |
class ViewControllerHeaderView: UIView { | |
@IBOutlet weak var userImageView: UIImageView! | |
@IBOutlet weak var messageButton: UIButton! |
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 UIKit | |
@propertyWrapper | |
struct Printer<T> { | |
public var currentValue: T? | |
var wrappedValue: T? { | |
get { | |
print("Property wrapper value printed", currentValue) |
OlderNewer