View LineFactory.swift
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 Foundation | |
class LineFactory { | |
static var lineCount : Int = 0 | |
static func makeLine() -> Line { | |
return Line() | |
} | |
class func randomLine() -> Line { | |
let line = Line() |
View 1MemoryDump.swift
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 Memory { | |
static func dump<T>(variable: inout T) { | |
withUnsafePointer(to: &variable) { print($0) } | |
} | |
static func dump(with: UnsafeRawPointer) { | |
let address = Int(bitPattern: with) | |
print(String(format:"%p", address)) | |
} | |
View AsyncFunc+objc.m
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
typedef void (^AVAssetImageGeneratorCompletionHandler)(CMTime, CGImageRef _Nullable, CMTime, AVAssetImageGeneratorResult, NSError * _Nullable); | |
// ... | |
- (void)generateCGImagesAsynchronouslyForTimes:(NSArray<NSValue *> *)requestedTimes | |
completionHandler:(AVAssetImageGeneratorCompletionHandler)handler; |
View RacyActor+Phase2.swift
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
var racyGlobal: [String] = [] | |
@MyGlobalActor | |
var safeGlobal: [String] = [] | |
class PlainOldClass { | |
var unprotectedState: String = [] | |
} | |
actor class RacyActor { |
View MyActor+phase1.swift
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
actor class MyActor { | |
let immutable: String = "42" | |
var mutableArray: [String] = [] | |
func synchronousFunction() { | |
mutableArray += ["syncFunction called"] | |
} | |
} | |
extension MyActor { |
View Dinner.swift
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
func makeDinner() async throws -> Meal { | |
async let veggies = try chopVegetables() | |
async let meat = marinateMeat() | |
async let oven = try preheatOven(temperature: 350) | |
let dish = Dish(ingredients: await [veggies, meat]) | |
return await try oven.cook(dish, duration: .hours(3)) | |
} |
View PlayerRefreshController+UIActor.swift
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
@UIActor | |
class PlayerRefreshController { | |
var players: [String] = [] | |
var gameSession: GameSession | |
func refreshPlayers() async { ... } | |
} |
View PlayerRefreshController+actor.swift
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
actor class PlayerRefreshController { | |
var players: [String] = [] | |
var gameSession: GameSession | |
func refreshPlayers() async { ... } | |
} |
View PlayerRefreshController.swift
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 PlayerRefreshController { | |
var players: [String] = [] | |
var gameSession: GameSession | |
var refreshQueue = DispatchQueue(label: "PlayerRefresh") | |
internal func refreshPlayers(completion: (() -> Void)? = nil) { | |
refreshQueue.async { | |
self.gameSession.allPlayers { players in | |
self.players = players.map(\.nickname) | |
completion?() |
View memory-layout.swift
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 Cocoa | |
var str = "Hello, playground" | |
let ptr = UnsafeRawPointer(str) | |
let origin = CGPoint(x: 0, y: 0) | |
var other = origin | |
other.x += 10 | |
var another = origin | |
another.y += 5 |
NewerOlder