Skip to content

Commit cf58468

Browse files
authored
Merge pull request #126 from sunshinejr/example-swift-containers
[Containers] Update Swift examples.
2 parents 3cd9413 + 89df4c8 commit cf58468

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

docs/_docs/containers-ascollectionnode.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ nextPage: containers-aspagernode.html
2222
</pre>
2323

2424
<pre lang="swift" class = "swiftCode hidden">
25-
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
25+
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
2626
</pre>
2727
</div>
2828
</div>
@@ -37,7 +37,7 @@ with your choice of **_one_** of the following methods
3737
- (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForItemAtIndexPath:(NSIndexPath *)indexPath
3838
</pre>
3939
<pre lang="swift" class = "swiftCode hidden">
40-
override func collectionNode(collectionNode: ASCollectionNode, nodeForItemAtIndexPath indexPath: NSIndexPath) -> ASCellNode
40+
override func collectionNode(_ collectionNode: ASCollectionNode, nodeForItemAt indexPath: IndexPath) -> ASCellNode
4141
</pre>
4242
</div>
4343
</div>
@@ -54,7 +54,7 @@ or
5454
- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath
5555
</pre>
5656
<pre lang="swift" class = "swiftCode hidden">
57-
override func collectionNode(collectionNode: ASCollectionNode, nodeBlockForItemAtIndexPath indexPath: NSIndexPath) -> ASCellNodeBlock
57+
override func collectionNode(_ collectionNode: ASCollectionNode, nodeBlockForItemAt indexPath: IndexPath) -> ASCellNodeBlock
5858
</pre>
5959
</div>
6060
</div>
@@ -96,7 +96,7 @@ Consider the following `-collectionNode:nodeBlockForItemAtIndexPath:` method.
9696
</pre>
9797

9898
<pre lang="swift" class = "swiftCode hidden">
99-
func tableNode(_ collectionNode: ASCollectionNode, nodeBlockForItemAt indexPath: IndexPath) -> ASCellNodeBlock {
99+
func collectionNode(_ collectionNode: ASCollectionNode, nodeBlockForItemAt indexPath: IndexPath) -> ASCellNodeBlock {
100100
guard photoFeed.count > indexPath.row else { return { ASCellNode() } }
101101

102102
let photoModel = photoFeed[indexPath.row]
@@ -130,13 +130,13 @@ An ASCollectionNode is assigned to be managed by an `ASViewController` in its `-
130130
<pre lang="objc" class="objcCode">
131131
- (instancetype)init
132132
{
133-
_flowLayout = [[UICollectionViewFlowLayout alloc] init];
133+
_flowLayout = [[UICollectionViewFlowLayout alloc] init];
134134
_collectionNode = [[ASCollectionNode alloc] initWithCollectionViewLayout:_flowLayout];
135135

136136
self = [super initWithNode:_collectionNode];
137137
if (self) {
138-
_flowLayout.minimumInteritemSpacing = 1;
139-
_flowLayout.minimumLineSpacing = 1;
138+
_flowLayout.minimumInteritemSpacing = 1;
139+
_flowLayout.minimumLineSpacing = 1;
140140
}
141141

142142
return self;
@@ -145,13 +145,13 @@ An ASCollectionNode is assigned to be managed by an `ASViewController` in its `-
145145

146146
<pre lang="swift" class = "swiftCode hidden">
147147
init() {
148-
flowLayout = UICollectionViewFlowLayout()
148+
flowLayout = UICollectionViewFlowLayout()
149149
collectionNode = ASCollectionNode(collectionViewLayout: flowLayout)
150150

151151
super.init(node: collectionNode)
152152

153-
flowLayout.minimumInteritemSpacing = 1
154-
flowLayout.minimumLineSpacing = 1
153+
flowLayout.minimumInteritemSpacing = 1
154+
flowLayout.minimumLineSpacing = 1
155155
}
156156
</pre>
157157
</div>
@@ -178,7 +178,7 @@ The `LocationCollectionNodeController` above accesses the `ASCollectionView` dir
178178
{
179179
[super viewDidLoad];
180180

181-
_collectionNode.delegate = self;
181+
_collectionNode.delegate = self;
182182
_collectionNode.dataSource = self;
183183
_collectionNode.view.allowsSelection = NO;
184184
_collectionNode.view.backgroundColor = [UIColor whiteColor];
@@ -189,10 +189,10 @@ The `LocationCollectionNodeController` above accesses the `ASCollectionView` dir
189189
override func viewDidLoad() {
190190
super.viewDidLoad()
191191

192-
collectionNode.delegate = self
192+
collectionNode.delegate = self
193193
collectionNode.dataSource = self
194194
collectionNode.view.allowsSelection = false
195-
collectionNode.view.backgroundColor = UIColor.whiteColor()
195+
collectionNode.view.backgroundColor = .white
196196
}
197197
</pre>
198198
</div>

docs/_docs/containers-aspagernode.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The main dataSource methods are:
2020
</pre>
2121

2222
<pre lang="swift" class = "swiftCode hidden">
23-
func numberOfPagesInPagerNode(pagerNode: ASPagerNode!) -> Int
23+
func numberOfPages(in pagerNode: ASPagerNode) -> Int
2424
</pre>
2525
</div>
2626
</div>
@@ -35,7 +35,7 @@ and
3535
</pre>
3636

3737
<pre lang="swift" class = "swiftCode hidden">
38-
func pagerNode(pagerNode: ASPagerNode!, nodeAtIndex index: Int) -> ASCellNode!
38+
func pagerNode(_ pagerNode: ASPagerNode, nodeAt index: Int) -> ASCellNode
3939
</pre>
4040
</div>
4141
</div>
@@ -50,7 +50,7 @@ or
5050
</pre>
5151

5252
<pre lang="swift" class = "swiftCode hidden">
53-
func pagerNode(pagerNode: ASPagerNode!, nodeBlockAtIndex index: Int) -> ASCellNodeBlock!
53+
func pagerNode(_ pagerNode: ASPagerNode, nodeBlockAt index: Int) -> ASCellNodeBlock
5454
</pre>
5555
</div>
5656
</div>
@@ -86,8 +86,8 @@ In the example below, you can see how the index is used to access the photo mode
8686
</pre>
8787

8888
<pre lang="swift" class = "swiftCode hidden">
89-
func pagerNode(pagerNode: ASPagerNode!, nodeBlockAtIndex index: Int) -> ASCellNodeBlock! {
90-
guard photoFeed.count > index else { return nil }
89+
func pagerNode(_ pagerNode: ASPagerNode, nodeBlockAt index: Int) -> ASCellNodeBlock {
90+
guard photoFeed.count > index else { return { ASCellNode() } }
9191

9292
let photoModel = photoFeed[index]
9393
let cellNodeBlock = { () -> ASCellNode in
@@ -123,8 +123,8 @@ One especially useful pattern is to return an `ASCellNode` that is initialized w
123123
</pre>
124124

125125
<pre lang="swift" class = "swiftCode hidden">
126-
func pagerNode(pagerNode: ASPagerNode!, nodeAtIndex index: Int) -> ASCellNode! {
127-
guard animals.count > index else { return nil }
126+
func pagerNode(_ pagerNode: ASPagerNode, nodeAt index: Int) -> ASCellNode {
127+
guard animals.count > index else { return ASCellNode() }
128128

129129
let animal = animals[index]
130130
let node = ASCellNode(viewControllerBlock: { () -> UIViewController in

docs/_docs/containers-asviewcontroller.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,16 @@ This table node is assigned to the `ASViewController` in its `-initWithNode:` de
4545
</pre>
4646

4747
<pre lang="swift" class = "swiftCode hidden">
48-
func initWithModel(models: Array&lt;Model&gt;) {
49-
let tableNode = ASTableNode(style:.Plain)
48+
init(models: [Model]) {
49+
let tableNode = ASTableNode(style: .plain)
5050

51-
super.initWithNode(tableNode)
51+
super.init(node: tableNode)
5252

53-
self.models = models
54-
55-
self.tableNode = tableNode
56-
self.tableNode.delegate = self
57-
self.tableNode.dataSource = self
58-
59-
return self
53+
self.models = models
54+
55+
self.tableNode = tableNode
56+
self.tableNode.delegate = self
57+
self.tableNode.dataSource = self
6058
}
6159
</pre>
6260
</div>

0 commit comments

Comments
 (0)