Skip to content

Instantly share code, notes, and snippets.

Avatar

Jung Kim godrm

  • Codesquad
  • Seoul, KOREA
  • Twitter @godrm
View GitHub Profile
@godrm
godrm / LineFactory.swift
Created Apr 6, 2022
HelloPlane 심볼 예제
View LineFactory.swift
import Foundation
class LineFactory {
static var lineCount : Int = 0
static func makeLine() -> Line {
return Line()
}
class func randomLine() -> Line {
let line = Line()
@godrm
godrm / 1MemoryDump.swift
Last active Aug 31, 2021
Swift Variable Address Dump to console
View 1MemoryDump.swift
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))
}
@godrm
godrm / AsyncFunc+objc.m
Created Nov 8, 2020
AsyncFunc by Objective-C
View AsyncFunc+objc.m
typedef void (^AVAssetImageGeneratorCompletionHandler)(CMTime, CGImageRef _Nullable, CMTime, AVAssetImageGeneratorResult, NSError * _Nullable);
// ...
- (void)generateCGImagesAsynchronouslyForTimes:(NSArray<NSValue *> *)requestedTimes
completionHandler:(AVAssetImageGeneratorCompletionHandler)handler;
View RacyActor+Phase2.swift
var racyGlobal: [String] = []
@MyGlobalActor
var safeGlobal: [String] = []
class PlainOldClass {
var unprotectedState: String = []
}
actor class RacyActor {
View MyActor+phase1.swift
actor class MyActor {
let immutable: String = "42"
var mutableArray: [String] = []
func synchronousFunction() {
mutableArray += ["syncFunction called"]
}
}
extension MyActor {
View Dinner.swift
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))
}
@godrm
godrm / PlayerRefreshController+UIActor.swift
Created Nov 8, 2020
PlayerRefreshController UIActor 클래스
View PlayerRefreshController+UIActor.swift
@UIActor
class PlayerRefreshController {
var players: [String] = []
var gameSession: GameSession
func refreshPlayers() async { ... }
}
@godrm
godrm / PlayerRefreshController+actor.swift
Created Nov 8, 2020
PlayerRefreshController Actor 클래스
View PlayerRefreshController+actor.swift
actor class PlayerRefreshController {
var players: [String] = []
var gameSession: GameSession
func refreshPlayers() async { ... }
}
@godrm
godrm / PlayerRefreshController.swift
Created Nov 8, 2020
PlayerRefreshController 클래스
View PlayerRefreshController.swift
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
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