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
final class ViewController: UIViewController { | |
@IBOutlet private weak var tableView: UITableView! | |
@IBOutlet private weak var searchTextField: UITextField! | |
@Filtered() var people: [Person] = [ | |
.init(name: "Luke Skywalker", height: 172, gender: "male"), | |
.init(name: "Darth Vader", height: 202, gender: "male"), | |
.init(name: "Leia Organa", height: 150, gender: "female"), | |
.init(name: "Owen Lars", height: 178, gender: "male"), |
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
@Filtered() var people: [Person] = [ | |
.init(name: "Luke Skywalker", height: 172, gender: "male"), | |
.init(name: "Darth Vader", height: 202, gender: "male"), | |
.init(name: "Leia Organa", height: 150, gender: "female"), | |
.init(name: "Owen Lars", height: 178, gender: "male"), | |
.init(name: "Beru Whitesun Lars", height: 165, gender: "female") | |
] |
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 Person: Filterable { | |
var name: String | |
var height: Int | |
var gender: String | |
var filterString: String { name + gender } | |
} |
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
protocol Filterable { | |
var filterString : String { get } | |
} |
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
final class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
URLProtocol.registerClass(MockURLProtocol.self) | |
guard let url = URL(string: "www.google.com.tr") else { return } | |
let request = URLRequest(url: url) | |
URLSession.shared.dataTask(with: request) { data, response, error in | |
guard let data = data, | |
let person = try? JSONDecoder().decode(Person.self, from: data) else { return } |
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
URLProtocol.registerClass(MockURLProtocol.self) |
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
final class MockURLProtocol: URLProtocol { | |
override class func canInit(with request: URLRequest) -> Bool { | |
true | |
} | |
override class func canonicalRequest(for request: URLRequest) -> URLRequest { request } | |
override func stopLoading() { } | |
override func startLoading() { | |
let jsonString = """ | |
{ |
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 Person: Codable { | |
var name: String | |
var age: Int | |
} |
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
final class MockURLProtocol: URLProtocol { | |
override class func canInit(with request: URLRequest) -> Bool { true } | |
override class func canonicalRequest(for request: URLRequest) -> URLRequest { request } | |
override func stopLoading() { } | |
} |
NewerOlder