Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumSwiftretain cycles and capture listsSingle-choice MCQ

Two closures returned from this function capture the same local variable. What does the code print?

func makeCounter() -> (() -> Int, () -> Void) { var n = 0 let get = { n } let inc = { n += 1 } return (get, inc) } let (get, inc) = makeCounter() inc(); inc() print(get())