Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mhdhejazi authored Apr 25, 2020
1 parent 3ab36d0 commit 23dfe6f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ var asUInt: UInt? { get }
var asSelector: Selector? { get }
```

### Objective-C block arguments

To pass a Swift closure as a block argument you need to add `@convention(block)` to the closure type:
```swift
typealias ResultBlock = @convention(block) (_ result: Int) -> Void
```
Now, just cast the closure to this type when passing it:
```swift
panel.beginSheetModalForWindow(window, completionHandler: { result in
print("result: ", result)
} as ResultBlock)
```

### Logging

It's always good to understand what's happening under the hood - be it to debug a problem or just out of curiosity.
Expand Down Expand Up @@ -214,10 +227,6 @@ let package = Package(
)
```

## Known issues

Calling a method with an Objective-C **block** argument is not supported (See [issue #1](https://github.com/mhdhejazi/Dynamic/issues/1)). Swift closures are entirely a different thing than Objective-C blocks, and [a bridging header will be required](https://academy.realm.io/posts/altconf-nikita-lutsenko-objc-swift-interoperability/#pitfalls-of-bridging-swift-and-objective-c-2122) to convert between them.

## TODO

- [ ] Write tests
Expand Down

0 comments on commit 23dfe6f

Please sign in to comment.