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 InputView { | |
enum Prompt : String { | |
case height = "> 사다리 높이를 입력해주세요.\n> " | |
case names = "> 참여할 사람 이름을 입력하세요.\n> " | |
} | |
static private func read(with prompt: Prompt) -> String { | |
print(prompt.rawValue) | |
let value = readLine() ?? "" | |
return value |
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
// | |
// archiver.swift | |
// | |
// Created by JK on 2020/02/27. | |
// Copyright © 2020 codesquad. All rights reserved. | |
// | |
import Foundation | |
class NBeverage : NSObject, NSCoding, Codable { |
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 UIKit | |
import OctoKit | |
import AuthenticationServices | |
extension URL { | |
/// Returns a new URL by adding the query items, or nil if the URL doesn't support it. | |
/// URL must conform to RFC 3986. | |
func appending(_ queryItems: [URLQueryItem]) -> URL? { | |
guard var urlComponents = URLComponents(url: self, resolvingAgainstBaseURL: true) else { | |
// URL is not conforming to RFC 3986 (maybe it is only conforming to RFC 1808, RFC 1738, and RFC 2732) |
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 countByCharacter(_ value: String) -> [Character: Int] { | |
var countMap = [Character: Int]() | |
for char in value { | |
let count = countMap[char] ?? 0 | |
countMap[char] = count + 1 | |
} | |
return countMap | |
} | |
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 { |