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
app.put("items", ":id") { req -> Item in | |
let id = req.parameters.get("id", as: UUID.self) | |
let updatedItem = try req.content.decode(Item.self) | |
return updatedItem | |
} |
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
app.post("items") { req -> Item in | |
let item = try req.content.decode(Item.self) | |
return item | |
} |
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
app.get("items") { req -> [Item] in | |
let item1 = Item(id: UUID(), name: "Item 1", description: "This is item 1.") | |
let item2 = Item(id: UUID(), name: "Item 2", description: "This is item 2.") | |
return [item1, item2] | |
} |
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 | |
struct Item: Codable { | |
var id: UUID | |
var name: String | |
var description: String | |
} |
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 | |
enum StatusType { | |
case information | |
case error(StatusErrorable) | |
} | |
struct StatusError: Error, StatusErrorable { | |
var message: String | |
var instructions: String |
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 XCTest | |
@testable import TinyViewController | |
class TinyViewControllerTests: XCTestCase { | |
func testSelectorAndTarget_getPassed_toViewControllerViewable() { | |
let vc = ViewController() | |
let dummyObject = DummyView(target: vc, selector: #selector(someSelector)) | |
vc.blueView = dummyObject | |
vc.loadView() |
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 { | |
lazy var blueView: ViewControllerView = { | |
let view = ViewControllerView(viewColor: .systemBlue, target: self, selector: #selector(presentAlert)) | |
return view | |
}() | |
override func loadView() { |
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 { | |
lazy var blueView: ViewControllerView = { | |
let view = ViewControllerView(viewColor: .systemBlue) | |
return view | |
}() | |
override func viewDidAppear(_ animated: Bool) { |
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 ViewControllerView: UIView { | |
private lazy var buttonStack: UIStackView = { | |
let stack = UIStackView(arrangedSubviews: [viewButton, alertButton]) | |
stack.translatesAutoresizingMaskIntoConstraints = false | |
stack.spacing = 12 | |
stack.axis = .vertical | |
return stack |
NewerOlder