Skip to content

Instantly share code, notes, and snippets.

View mkchoi212's full-sized avatar
🎯
Focusing

Mike JS. Choi mkchoi212

🎯
Focusing
View GitHub Profile
@mkchoi212
mkchoi212 / optional_escape.swift
Last active December 28, 2017 19:58
Optional closures are escaping by default
struct RandData {
let parse: (String) -> (String)
}
// Note: There is no @escaping and no compiler warnings occur when parseFunc
// escapes the scope by being stored off to RandData struct.
//
// parseFunc can not be used as nonescaping since optional closures
// are also automatically escaping
func parseString(input: String, parseFunc: ((String) -> (String))?) {
@mkchoi212
mkchoi212 / func_var_escape.swift
Last active December 28, 2017 19:59
Examples for escaping, no-escaping closures in Swift
struct Resource {
let parse : (String) -> (String)
}
// parseFunc is escaping createResource's scope by being stored off to
// randResource's parse variable
func createResource(parseFunc: @escaping (String) -> (String)) -> Resource{
let randResource = Resource(parse: parseFunc)
return randResource
}