Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyvar committed Aug 20, 2018
1 parent 39fe1ea commit 696a082
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions README.md
Expand Up @@ -31,7 +31,7 @@ present(vc, shouldExit: ward(self, else: true) { strongSelf
})
```

Or, you can change your function declaration to a computed `var`, and use the `KeyPath` based API:
Use the `KeyPath` based API to call blocks that are properties of ```self```

```swift
class MyViewController: UIViewController {
Expand All @@ -40,20 +40,25 @@ class MyViewController: UIViewController {
super.viewDidLoad()

useAClosureBasedAPI(block: ward(self, \.handleSomething))
useAClosureBasedAPI(block: ward(self, \.handleAnotherThing))
}

var handleSomething: (_ something: Any) -> Void {
return { any in
...
}
// Can't access functions with KeyPath so blocks are required
let handleSomething: (_ something: Any) -> Void = { something in
...
}

// lazy because accessing self
lazy var handleSomething: (_ something: Any) -> Void = { something in
self.doThing(with: something)
}
}
```

Plays well with generic inputs & outputs, too!

```swift
let function: (String) -> Int = ward(self) { strongSelf, string in
lazy var function: (String) -> Int = ward(self) { strongSelf, string in
return strongSelf.stringToInt(string)
}
```
Expand Down

0 comments on commit 696a082

Please sign in to comment.