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 | |
// First one fails to be decoded. | |
// | |
// [1] dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Unescaped control character '0xa' around line 2, column 0." UserInfo={NSJSONSerializationErrorIndex=16, NSDebugDescription=Unescaped control character '0xa' around line 2, column 0.}))) | |
// [2] Success! | |
// | |
// SeeAlso: https://github.com/apple/swift-evolution/blob/main/proposals/0200-raw-string-escaping.md | |
let literalJSONishString = """ |
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
#!/bin/bash | |
# プロジェクトファイルのパス | |
PROJECT_PATH="YourProject.xcodeproj" | |
# スキーム名 | |
SCHEME_NAME="YourScheme" | |
# シミュレータのデバイス名 | |
SIMULATOR_DEVICE_NAME="iPhone 12" |
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
/// 弁(Valve)のように値がこなくなったら自動的に元の値に戻るProperty。 | |
/// 元に戻る時間も指定できる。 | |
@propertyWrapper | |
struct ValveProperty<Value> { | |
private let relay: BehaviorRelay<Value> | |
private let property: Property<Value> | |
init( | |
automaticallyTogglesToInitialValue initialValue: Value, | |
afterInterval interval: RxTimeInterval = .milliseconds(1000), |
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
// comparing atomic operation performance | |
import Foundation | |
final class Locking { | |
static let shared = Locking() | |
private(set) var isLocked: Bool = false | |
private let _lock = NSLock() |
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
// comparing atomic operation performance | |
import Concurrency | |
import Foundation | |
final class Locking { | |
static let shared = Locking() | |
private(set) var isLocked: Bool = false |
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
{% for enum in types.enums %} | |
// MARK: {{ enum.name }} | |
extension {{ enum.name }} { | |
{% for case in enum.cases %} | |
{{ enum.accessLevel }} var is{{ case.name|upperFirstLetter }}: Bool { | |
switch self { case .{{ case.name }}: return true; default: return false; } | |
} | |
{% endfor %} | |
} | |
{% endfor %} |
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 | |
let smp = DispatchSemaphore(value: 1) | |
let smp1 = DispatchSemaphore(value: 0) | |
func doSomething() { | |
for i in (0..<4) { | |
smp.wait() | |
print("[\(i * 3)]") | |
defer { |
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
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"time" | |
) | |
func main() { |
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
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"time" | |
) | |
func main() { |
NewerOlder