You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+95Lines changed: 95 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,8 @@ Here's list of Swift tips & tricks with all additional sources (playgrounds, ima
8
8
9
9
## 📃 Table of contents
10
10
11
+
[#59`AlertPresentable` protocol]()<br />
12
+
[#58 CollectionView extension for adaptive grid layout]()<br />
11
13
[#57 Render HTML within a `UILabel`](https://github.com/Luur/SwiftTips#57-render-html-within-a-uilabel)<br />
12
14
[#56 Custom `Error` by adopting `LocalizedError` protocol](https://github.com/Luur/SwiftTips#56-custom-error-by-adopting-localizederror-protocol)<br />
13
15
[#55 'Result' type without value to provide](https://github.com/Luur/SwiftTips#55-result-type-without-value-to-provide)<br />
@@ -66,6 +68,99 @@ Here's list of Swift tips & tricks with all additional sources (playgrounds, ima
66
68
[#2 Easy way to hide Status Bar](https://github.com/Luur/SwiftTips#2-easy-way-to-hide-status-bar)<br />
67
69
[#1 Safe way to return element at specified index](https://github.com/Luur/SwiftTips#1-safe-way-to-return-element-at-specified-index)<br />
68
70
71
+
## [#59`AlertPresentable` protocol]()
72
+
73
+
In my current project I work on I present alerts almost on every view controller. To reduce lines of codes and time spent on duplicate code I created `AlertPresentable` layer and want to share it with you.
74
+
Any `ViewController` which implements `AlertPresentable` protocol receive opportunity to present any type of alerts discribed in this layer just by one line of code.
presentConfirmationAlert(with: "Are you sure you would like to sign out?") { _in
122
+
// sign out user
123
+
}
124
+
}
125
+
}
126
+
```
127
+
128
+
Back to [Top](https://github.com/Luur/SwiftTips#-table-of-contents)
129
+
130
+
## [#58 CollectionView extension for adaptive grid layout]()
131
+
132
+
Implementation of grid CollectionView layout is a commont task. But I found that calculation of cell width when you dont know how many cells can fit in one row of CollectionView is not a common task.
133
+
134
+
Here is my extension for calculation width of cell in grid CollectionView to make your layot adaptive.
let cellWidth = collectionView.flexibleCellWidth(minCellWidth: 72, minimumInteritemSpacing: 10)
154
+
returnCGSize(width: cellWidth, height: cellWidth)
155
+
}
156
+
```
157
+
158
+
iPhoneSE 
159
+
160
+
iPhoneX 
161
+
162
+
Back to [Top](https://github.com/Luur/SwiftTips#-table-of-contents)
163
+
69
164
## [#57 Render HTML within a `UILabel`]()
70
165
71
166
You can render HTML strings within a `UILabel` using a special initializer of `NSAttributedString` and passing in `NSAttributedString.DocumentType.html` for `.documentType`. But in most cases it is not enough to display it as is. If we want to add custom font or color we need to use CSS (add CSS header to our HTML string).
0 commit comments