This file contains hidden or 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
enum PopTeamEpic: String { | |
case po = "ポ" | |
case p = "プ" | |
case teame = "テピ" | |
case pic = "ピック" | |
} | |
struct 蒼井翔太: Sequence, IteratorProtocol { | |
mutating func next() -> PopTeamEpic? { | |
switch arc4random_uniform(4) { | |
case 0: return .po |
This file contains hidden or 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 Lazy <T> { | |
private var t: T? | |
private let initializer: () -> T | |
private let semaphore = DispatchSemaphore(value: 1) | |
init(_ initializer: @escaping () -> T) { | |
self.initializer = initializer |
This file contains hidden or 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
let myVariable: Int = { while(true) {} }() |
This file contains hidden or 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
protocol TestProtocol { | |
associatedtype Element | |
} | |
struct TestStruct<Element>: TestProtocol { | |
let element: Element | |
} | |
// error: type 'TestStruct<Element>' does not conform to protocol 'TestProtocol' |
This file contains hidden or 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
let string = "123" | |
let scanner = Scanner(string: string) | |
var int = NSNotFound | |
scanner.scanInt(&int) | |
print(int) |
This file contains hidden or 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 C: NSObject { | |
} | |
struct D { | |
unowned let x: C | |
} |
This file contains hidden or 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
infix operator ± : RangeFormationPrecedence | |
extension Numeric where Self: Comparable { | |
public static func ± (lhs: Self, rhs: Self) -> ClosedRange<Self> { | |
let added = lhs + rhs | |
let subtracted = lhs - rhs | |
let lowerBound = min(added, subtracted) | |
let upperBound = max(added, subtracted) | |
return lowerBound ... upperBound |
This file contains hidden or 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
let base = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 400)) | |
base.backgroundColor = .white | |
PlaygroundPage.current.liveView = base | |
let view = UIView(frame: CGRect(x: 100, y: 100, width: 200, height: 200)) | |
view.backgroundColor = .blue | |
base.addSubview(view) | |
// アニメーションブロック | |
UIView.animate(eachBlockDuration: 1, eachBlockDelay: 0, eachBlockOptions: .curveEaseInOut, animationBlocks: |
This file contains hidden or 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
extension Int { | |
static func `init`(float: Float) -> Float { | |
return float | |
} | |
} | |
let float = Int(float: 3.14) | |
print(float) |
This file contains hidden or 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 age = 28 | |
let unknown = withUnsafePointer(to: &age) { $0.advanced(by: 12).pointee } | |
print(unknown) // 7597125269629269102 |