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
enum Status { | |
case notStarted | |
case ongoing | |
case ended | |
} | |
enum Team { | |
case first | |
case second | |
} |
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
struct Match { | |
var score: Int | |
init(score: Int) { | |
self.score = score | |
} | |
} | |
func finish(_ match: inout Match) { // Added "inout" keyword | |
match.score = 100 // Updating the score here changes the score on the original copy |
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
class Match { | |
var score: Int | |
init(score: Int) { | |
self.score = score | |
} | |
} | |
func finish(_ match: Match) { | |
match.score = 100 // Updating the score here changes the score on the original copy |
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
// Our Original class | |
class Example { | |
// Original function | |
static func start() { | |
print("Start") | |
} | |
} | |
// Subclassing |
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
// Our Original class | |
class Example { | |
// Original function | |
class func start() { | |
print("Start") | |
} | |
} | |
// Subclassing |
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
let url = URL(string: "http://jsonplaceholder.typicode.com/posts")! | |
AF.request(url) | |
.responseDecodable(of: [Post].self) { (response) in | |
guard let posts = response.value else { return completion([]) } | |
completion(posts) | |
} |
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
let url = URL(string: "http://jsonplaceholder.typicode.com/posts")! | |
let task = URLSession.shared.dataTask(with: url, completionHandler: { data, response, error in | |
guard let data = data else { return completion([]) } | |
do { | |
let posts = try JSONDecoder().decode([Post].self, from: data) | |
completion(posts) | |
} catch { | |
print(error) | |
completion([]) | |
} |
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
struct Post { | |
let userID, id: Int | |
let title, body: String | |
} | |
extension Post: Decodable { | |
enum CodingKeys: String, CodingKey { | |
case userID = "userId" | |
case id, title, body | |
} |
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 UIKit | |
final class TableViewAdapter: NSObject, UITableViewDataSource { | |
let tableView: UITableView | |
init(tableView: UITableView) { | |
self.tableView = tableView | |
super.init() |
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 UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var tableView: UITableView! | |
private var adapter: TableViewAdapter! | |
override func viewDidLoad() { | |
super.viewDidLoad() |
NewerOlder