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 |
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?() |
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 { ... } | |
} |
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 { ... } | |
} |
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)) | |
} |
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 { |
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 { |
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; |
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)) | |
} | |
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() |
OlderNewer