Skip to content

Instantly share code, notes, and snippets.

View aataraxiaa's full-sized avatar
:octocat:
Focusing

Pete Smith aataraxiaa

:octocat:
Focusing
  • DuckDuckGo
  • 05:31 (UTC)
View GitHub Profile
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
let convertedPoint = button.convert(point, from: self)
return button.point(inside: convertedPoint, with: event)
}
actor GoodActor {
var count: Int = 0
let limit = 5
func displayAndUpdate() {
guard count < 5 else {
return
}
final class DataRacer {
var count: Int = 0
let limit = 5
func displayAndUpdate() {
guard count < 5 else {
return
}
func fetchDataPair(from urls: (URL, URL)) async throws -> (ModelWrapper, ModelWrapper) {
async let resultOne = fetchData(from: urls.0)
async let resultTwo = fetchData(from: urls.1)
return try await (resultOne, resultTwo)
}
func fetchDataPair(from urls: (URL, URL)) async throws -> (ModelWrapper, ModelWrapper) {
let resultOne = try await fetchData(from: urls.0)
let resultTwo = try await fetchData(from: urls.1)
return (resultOne, resultTwo)
}
func fetchData(from url: URL) async throws -> ModelWrapper {
let (data, _) = try await URLSession.shared.data(from: url)
let model = try JSONDecoder().decode(Model.self, from: data)
let (imageData, _) = try await URLSession.shared.data(from: model.imageURL)
guard let image = UIImage(data: imageData) else {
throw APIErrors.imageDecodingError
}
return ModelWrapper(model: model, image: image)
}
struct Model: Decodable {
let id: Int
let name: String
let imageURL: URL
}
struct ModelWrapper {
let model: Model
let image: UIImage
}
func fetchData(from url: URL, withCompletion completion: @escaping (Result<ModelWrapper, Error>) -> Void) -> Void {
let firstTask = URLSession.shared.dataTask(with: url) { data, response, error in
if let error = error {
completion(.failure(error))
// 😱 DID NOT RETURN!
}
guard let data = data else {
final class ShowBugTestCase: BaseTestCase {
let showBugRobot = ShowBugRobot()
func testShowBugButtonsDisplaysAlert() {
// When
showBugRobot
.tapShowBugButton()
// Then
import XCTest
let app = XCUIApplication()
class BaseTestCase: XCTestCase {
override func setUpWithError() throws {
continueAfterFailure = false
app.launch()
}