Skip to content

Instantly share code, notes, and snippets.

DispatchQueue.main.async {
// execute async on main thread
}
class CustomThread: Thread {
override func main() {
do_something
}
}
let customThread = CustomThread()
customThread.start()
let task = Process()
task.launchPath = "/bin/sh" //executable you want to run
task.arguments = arguments //here is the information you want to pass
task.terminationHandler = {
// do here something in case the process terminates
}
task.launch()
func method2() {
statement1 {
callback1()
}
statement2
}
func method1() {
statement1()
statement2()
statement3()
statement4()
}
var paws: MonkeyPaws?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if CommandLine.arguments.contains("--MonkeyPaws") {
paws = MonkeyPaws(view: window!)
}
return true
}
func testMonkey() {
let application = XCUIApplication(bundleIdentifier: "de.olbrich.jan.SnapshotTesting")
_ = application.descendants(matching: .any).element(boundBy: 0).frame
let monkey = Monkey(frame: application.frame)
monkey.addDefaultUIAutomationActions()
monkey.addXCTestTapAlertAction(interval: 100, application: application)
monkey.monkeyAround()
}
func getRandomCoordinate() -> XCUICoordinate {
let x = CGFloat(Float(arc4random()) / Float(UINT32_MAX))
let y = CGFloat(Float(arc4random()) / Float(UINT32_MAX))
let vector = CGVector(dx: x, dy: y)
let coordinate = getCoordinateForVector(vector: vector)
return coordinate
}
// our algorithm has this signature
func isCorrectEmail(email Email) -> Bool
property("emails should always be correct") <- forAll { (email: Email) in
return isCorrectEmail(email)
}
extension Email: Arbitray {
public static var arbitrary: Gen<Email> {
return Gen.compose { comp in
return Email(comp.generate(localEmail), comp.generate(hostname), comp.generate(tld))
}
}
}