Skip to content

Commit 9de8936

Browse files
authored
Moar typos in README
1 parent 7c47f7c commit 9de8936

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ let cell = tableView.dequeueReusableCell(for: indexPath) as MyCustomCell
226226
let cell: MyCustomCell = tableView.dequeueReusableCell(for: indexPath)
227227
```
228228

229-
As long as **Swift can use type-inference to understand that you'll want a cell of type `MyCustomCell`** (either using `as MyCystomCell` or explicitly typing the receiving variable `cell: MyCustomCell`), it will magically infer both the cell class to use and thus its `reuseIdentifier` needed to dequeue the cell, and which exact type to return to save you a type-cast.
229+
As long as **Swift can use type-inference to understand that you'll want a cell of type `MyCustomCell`** (either using `as MyCustomCell` or explicitly typing the receiving variable `cell: MyCustomCell`), it will magically infer both the cell class to use and thus its `reuseIdentifier` needed to dequeue the cell, and which exact type to return to save you a type-cast.
230230

231231
* No need for you to manipulate `reuseIdentifiers` Strings manually anymore!
232232
* No need to force-cast the returned `UITableViewCell` instance down to your `MyCustomCell` class either!
@@ -255,7 +255,7 @@ extension MyViewController: UITableViewDataSource {
255255

256256
Now all you have is **a beautiful code and type-safe cells**, with compile-type checking, and no more String-based API!
257257

258-
> 💡 If the cell class is computed at runtime in a variable, you won't be able to use `as theVariable` or `let cell: theVariable` obviously… but instead you can use the optional parameter `cellType` (which otherwise gets infered by the return type and is thus not necessary to provide explicitly)
258+
> 💡 If the cell class you want to dequeue is computed at runtime and stored in a variable, you won't be able to use `as theVariable` or `let cell: theVariable` obviously. Instead, you can use the optional parameter `cellType` (which otherwise gets infered by the return type and is thus not necessary to provide explicitly)
259259
>
260260
> <details>
261261
> <summary>📑 Example with a cell type determined at runtime</summary>
@@ -266,15 +266,17 @@ Now all you have is **a beautiful code and type-safe cells**, with compile-type
266266
> class Child2Cell: ParentCell {}
267267
>
268268
> func cellType(for indexPath: NSIndexPath) -> ParentCell.Type {
269-
> return (indexPath.row % 2 == 0) ? Child1Cell.self : Child2Cell.self
269+
> return indexPath.row.isMultiple(of: 2) ? Child1Cell.self : Child2Cell.self
270270
> }
271271
>
272272
> func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
273273
> let cellClass = self.cellType(for: indexPath)
274274
> // As `self.cellType(for:)` always returns a `ParentCell` (sub-)class, the type
275275
> // of the variable `cell` below is infered to be `ParentCell` too. So only methods
276276
> // declared in the parent `ParentCell` class will be accessible on the `cell` variable.
277+
> // But this code will still dequeue the proper type of cell (Child1Cell or Child2Cell).
277278
> let cell = tableView.dequeueReusableCell(for: indexPath, cellType: cellClass)
279+
> // Then fill the content of your cell (using methods/properties from `ParentCell` type)
278280
> return cell
279281
> }
280282
> ```
@@ -286,7 +288,7 @@ Now all you have is **a beautiful code and type-safe cells**, with compile-type
286288
287289
# Type-safe XIB-based reusable views
288290
289-
`Reusable` also allows you to create reusable custom views designed in Interface Builder to reuse them in other XIBs or by code, like creating custom UI widgets used in multiple places in your app.
291+
`Reusable` also allows you to create reusable custom views designed in Interface Builder to reuse them in other XIBs or Storyboards, or by code. This allows you to treat those views like custom UI widgets that can be used in multiple places in your app.
290292
291293
## 1. Declare your views to conform to `NibLoadable` or `NibOwnerLoadable`
292294
@@ -304,7 +306,7 @@ final class NibBasedFileOwnerView: UIView, NibOwnerLoadable { /* and that's it!
304306
```
305307
306308
> 💡 You should use the second approach if you plan to use your custom view in another XIB or Storyboard.
307-
> This will allow you to just drop a UIView in a XIB/Storyboard and change its class to the class of your custom XIB-based view to use it. That custom view will then automagically load its own content from the associated XIB when instantiated by the storyboard containing it, without having to write additional code to load the content of the custom view manually every time.
309+
> This will allow you to just drop a UIView in a XIB/Storyboard and change its class in IB's inspector to the class of your custom XIB-based view to use it. That custom view will then automagically load its own content from the associated XIB when instantiated by the storyboard containing it, without having to write additional code to load the content of the custom view manually every time.
308310
309311
## 2. Design your view in Interface Builder
310312

@@ -339,21 +341,21 @@ final class MyCustomWidget: UIView, NibOwnerLoadable {
339341
```
340342
</details>
341343

342-
Then that widget can be integrated in a Storyboard Scene (or any other XIB) by simply dropping a `UIView` on the Storyboard, and changing its class to `MyCustomWidget`.
344+
Then that widget can be integrated in a Storyboard Scene (or any other XIB) by simply dropping a `UIView` on the Storyboard, and changing its class to `MyCustomWidget` in IB's inspector.
343345

344346
<details>
345347
<summary>🖼 Example of a `NibOwnerLoadable` custom view once integrated in another Storyboard</summary>
346348

347349
* In the capture below, all blue square views have a custom class of `MyCustomWidget` set in Interface Builder.
348-
* When selecting one of this custom class, you have direct access to all `@IBOutlet` that this `MyCustomWidget` exposes, which allows you to connect them to other views of the Storyboard if needed
349-
* When selecting one of this custom class, you also have access to all the `@IBInspectable` properties. For example, in the capture below, you can see the "Rect color" and "Text" inspectable properties on the right panel, that you can change right from the Storyboard integrating your custom widget.
350+
* When selecting one of these custom views, you have direct access to all `@IBOutlet` that this `MyCustomWidget` exposes, which allows you to connect them to other views of the Storyboard if needed
351+
* When selecting one of these custom views, you also have access to all the `@IBInspectable` properties. For example, in the capture below, you can see the "Rect color" and "Text" inspectable properties on the right panel, that you can change right from the Storyboard integrating your custom widget.
350352

351353
![NibOwnerLoadable integrated in a Storyboard](NibOwnerLoadable-InStoryboard.png)
352354
</details>
353355

354356
## 3a. Auto-loading the content of a `NibOwnerLoadable` view
355357

356-
If you used `NibOwnerLoadable` and made your custom view the File's Owner of your XIB, you should then override `init?(coder:)` so that it load it's associated XIB as subviews and add constraints automatically:
358+
If you used `NibOwnerLoadable` and made your custom view the File's Owner of your XIB, you should then override `init?(coder:)` so that it loads it's associated XIB as subviews and add constraints automatically:
357359

358360
```swift
359361
final class MyCustomWidget: UIView, NibOwnerLoadable {
@@ -365,9 +367,11 @@ final class MyCustomWidget: UIView, NibOwnerLoadable {
365367
}
366368
```
367369

368-
Overriding `init?(coder:)` allows your `MyCustomWidget` custom view to load its content from the associated XIB `MyCustomWidget.xib` and add it as subviews of itself.
370+
`self.loadNibContent()` is a method provided by the `NibOwnerLoadable` mixin. It basically loads the content from the associated `MyCustomWidget.xib`, then add all the root views in that XIB as subviews of your `MyCustomWidget`, with appropriate layout constraints to make them the same size as your `MyCustomWidget` container view.
369371

370-
_💡 Note: it is also possible to override `init(frame:)`, in order to be able to create an instance of that view programatically and call `loadNibContent()` to fill with views if needed._
372+
Overriding `init?(coder:)` and calling `self.loadNibContent()` thus allows you to have that content automatically loaded by the system when that `MyCustomWidget` in included in another XIB or in a Storyboard (as `init?(coder:)` is the `init` that is called by iOS to create those instances in a XIB or Storyboard)
373+
374+
_💡 Note: it is also possible to override `init(frame:)` similarly, in order to be able to also create an instance of that view manually via code if needed._
371375

372376
## 3b. Instantiating a `NibLoadable` view
373377

0 commit comments

Comments
 (0)