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 fixBoxes() { | |
// fixes punctuation in a string: mixed LTR/RTL text causes punctuation at the end to appear at the beginning of the string | |
function fix(str) { | |
var match = str.match(/^[\!\?"]+/); // find !, ?, and " at the beginning of a string | |
if (match) { | |
return str.substring(match[0].length) + match[0]; // and move it to the end | |
} | |
return str; | |
} | |
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
// call like: asyncify(runRequest)(arg) { success in ... } | |
func asyncify<P, R>(_ function: @escaping (P) throws -> (R)) -> ((P, _ completion: @escaping ((Result<R>) -> Void)) -> Void) { | |
return { (arg: P, completion: @escaping (Result<R>) -> Void) in | |
DispatchQueue.global(qos: .background).async { | |
do { | |
let result = try function(arg) | |
DispatchQueue.main.async { | |
completion(.success(result)) | |
} | |
} catch let error { |
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 | |
public extension UIView { | |
public var width: CGFloat { | |
set { | |
bounds.size.width = newValue | |
} | |
get { | |
return bounds.size.width | |
} |
OlderNewer