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
private extension WKWebView { | |
func getUserAgent() async throws -> String? { | |
try await withCheckedThrowingContinuation { continuation in | |
evaluateJavaScript("navigator.userAgent") { (result, error) in | |
if let error { | |
continuation.resume(throwing: error) | |
} else if let userAgent = result as? String { | |
continuation.resume(returning: userAgent) | |
} | |
} |
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
extension UIView { | |
var recursiveSubviews: [UIView] { | |
subviews + subviews.flatMap(\.recursiveSubviews) | |
} | |
func printViewHierarchy(depth: Int = 0) { | |
for subview in subviews { | |
print("\(String(repeating: " ", count: depth))- \(String(describing: type(of: subview)))") | |
subview.printViewHierarchy(depth: depth + 1) | |
} |
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
/// 指定した桁数で2進数を表示する、0埋め | |
func formatBinary8(_ num: UInt8, digits: Int = 8) -> String { | |
let s = String(num, radix: 2) | |
return s.count < digits | |
? String(repeating: "0", count: digits - s.count) + s | |
: s | |
} |
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
/// パスから末尾の拡張子を取得する | |
function getFileExtension(path) { | |
let splitted= url.split("."); | |
return splitted[splitted.length - 1]; | |
} | |
/// Google Driveのルート直下の指定の名前の | |
/// フォルダを作成または取得する | |
function getTargetFolder(folderName) { | |
let rootFolder = DriveApp.getRootFolder(); |
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 | |
final class WeakObject<T: AnyObject> { | |
weak var _object: T? | |
init(_ object: T) { | |
_object = object | |
} | |
} |
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
private func _hexString<I: BinaryInteger>(_ value: I) -> String { | |
"0x" + String(value, radix: 16) | |
} | |
extension Character { | |
func hexRepresentation() -> String { | |
unicodeScalars | |
.map { _hexString($0.value) } | |
.joined(separator: ", ") | |
} |
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
extension AVAsset { | |
private func _generator(size: CGSize) -> AVAssetImageGenerator { | |
let generator = AVAssetImageGenerator(asset: self) | |
generator.maximumSize = size | |
generator.appliesPreferredTrackTransform = true | |
return generator | |
} | |
func extractUIImageAsync(size: CGSize) -> Single<UIImage?> { | |
let generator = _generator(size: size) |
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 extension KeyedDecodingContainerProtocol { | |
func decode<T: Decodable>(forKey key: Key) throws -> T { | |
try decode(T.self, forKey: key) | |
} | |
func decodeSafe<T: Decodable>(forKey key: Key, defaultValue: T) -> T { | |
(try? decode(T.self, forKey: key)) ?? defaultValue | |
} | |
} |
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 | |
public protocol EmptyInitializable { | |
init() | |
} | |
extension Int: EmptyInitializable {} | |
extension String: EmptyInitializable {} | |
extension Array: EmptyInitializable {} | |
extension Bool: EmptyInitializable {} |
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
// | |
// UIKit+lerp.swift | |
// ha1f | |
// | |
extension CGRect { | |
/// 線形補間した中間矩形を返す | |
/// - parameter otherRect: 目指す先の矩形 | |
/// - parameter rate: 0-1の間の値。0なら自分と、1ならotherRectと同じ。 | |
func lerp(_ otherRect: CGRect, rate: CGFloat) -> CGRect { |
NewerOlder