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
public struct ArraySlice<Element> { | |
... | |
@inlinable public func map<T>(_ transform: (Element) throws -> T) rethrows -> [T] | |
... | |
} |
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
// https://ko.wikipedia.org/wiki/함자_(수학) | |
struct F<X> { | |
let x : X? | |
init(_ x: X?) { self.x = x } | |
func map<Y>(_ f : @escaping (X) -> Y?) -> F<Y> { | |
guard let x = self.x else { | |
return F<Y>(nil) |
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 | |
DispatchQueue.global().sync { | |
print("hi") | |
} | |
print("good") | |
let serial = DispatchQueue(label: "Serial") |
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 AVFoundation | |
// Get H264/HEVC Parameter Set | |
private func getParameterSet(_ sampleBuffer: CMSampleBuffer) -> Data { | |
var parameterSet = Data() | |
let codecStartCode = [UInt8](arrayLiteral: 0x00, 0x00, 0x00, 0x01) | |
parameterSet.append(contentsOf: codecStartCode) | |
let description = CMSampleBufferGetFormatDescription(sampleBuffer)! | |
var numParams = 0 |
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 | |
extension ExpressibleByIntegerLiteral { | |
var bytes: [UInt8] { return withUnsafeBytes(of: self) { Array($0) } } | |
} | |
var id = UInt8(exactly: 1)! | |
var count = UInt8(exactly: 2)! | |
var timeStart = UInt64(exactly: 0x1234567898765432)! | |
var timeEnd = UInt64(exactly: 4)! |
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 | |
protocol Receivable { | |
init?(from: Data) | |
} | |
extension Receivable where Self: Decodable { | |
init?(from jsonData: Data) { | |
guard let decoded = try? JSONDecoder().decode(Self.self, from: jsonData) else { return nil } | |
self = decoded |
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 Moya | |
import Foundation | |
guard let case MoyaError.underlying(nsError as NSError, _) = error else { return } | |
let unknownHostError = [ | |
NSURLErrorUnknown, | |
NSURLErrorCannotFindHost, | |
NSURLErrorDomain, | |
NSURLErrorCancelled, |
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 | |
class CustomButton { | |
var containingTouchViews: [UIView] = [] | |
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool { | |
self.containingTouchViews | |
.map { view in | |
view.frame.contains(self.convert(point, to: view)) | |
// below codes are optional |
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
/* | |
id.txt example: | |
stringid1 | |
stringid2 | |
... | |
eng.txt example: | |
hello |