Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 0dc0179

Browse files
committed
Merge pull request #1012 from NatashaTheRobot/master
[Swift] Add Readme code snippet with example usage of an ASDisplayNode.
2 parents 4c4f0c8 + 90af0d3 commit 0dc0179

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ dispatch_async(_backgroundQueue, ^{
5757
});
5858
```
5959
60+
In Swift:
61+
62+
```swift
63+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) {
64+
let node = ASTextNode()
65+
node.attributedString = NSAttributedString(string: "hello")
66+
node.measure(CGSize(width: screenWidth, height: CGFloat.max))
67+
node.frame = CGRect(origin: CGPointZero, size: node.calculatedSize)
68+
69+
// self.view isn't a node, so we can only use it on the main thread
70+
dispatch_async(dispatch_get_main_queue()) {
71+
self.view.addSubview(node.view)
72+
}
73+
}
74+
```
75+
6076
AsyncDisplayKit at a glance:
6177

6278
* `ASImageNode` and `ASTextNode` are drop-in replacements for UIImageView and

0 commit comments

Comments
 (0)