@@ -31,40 +31,13 @@ extension AnimationType {
3131 }
3232}
3333
34- // MARK: - AlertIcon
35- extension AlertIcon {
36- var text : String {
37- switch self {
38- case . heart: return " Heart "
39- case . doc: return " Doc "
40- case . bookmark: return " Bookmark "
41- case . moon: return " Moon "
42- case . star: return " Star "
43- case . exclamation: return " Exclamation "
44- case . flag: return " Flag "
45- case . message: return " Message "
46- case . question: return " Question "
47- case . bolt: return " Bolt "
48- case . shuffle: return " Shuffle "
49- case . eject: return " Eject "
50- case . card: return " Card "
51- case . rotate: return " Rotate "
52- case . like: return " Like "
53- case . dislike: return " Dislike "
54- case . privacy: return " Privacy "
55- case . cart: return " Cart "
56- case . search: return " Search "
57- }
58- }
59- }
60-
6134// MARK: - ViewController
6235class ViewController : UITableViewController {
6336
6437 @IBOutlet var cellText : UITableViewCell !
6538
6639 var animations = AnimationType . allCases
67- var alerticons = AlertIcon . allCases
40+ var symbols : [ String ] = [ ]
6841
6942 var actions1 : [ String ] = [ ]
7043 var actions2 : [ String ] = [ ]
@@ -92,6 +65,10 @@ class ViewController: UITableViewController {
9265 super. viewDidLoad ( )
9366 title = " ProgressHUD "
9467
68+ DispatchQueue . main. async {
69+ self . loadSymbols ( )
70+ }
71+
9572 actions1. append ( " Animation - No text " )
9673 actions1. append ( " Animation - Short text " )
9774 actions1. append ( " Animation - Longer text " )
@@ -105,6 +82,8 @@ class ViewController: UITableViewController {
10582 actions3. append ( " Progress - 60% " )
10683 actions3. append ( " Progress - 90% " )
10784
85+ actions4. append ( " Symbol - No text " )
86+ actions4. append ( " Symbol - Short text " )
10887 actions4. append ( " Success - No text " )
10988 actions4. append ( " Success - Short text " )
11089 actions4. append ( " Error - No text " )
@@ -158,7 +137,7 @@ extension ViewController {
158137extension ViewController {
159138
160139 override func numberOfSections( in tableView: UITableView ) -> Int {
161- return 9
140+ return 8
162141 }
163142
164143 override func tableView( _ tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
@@ -171,32 +150,30 @@ extension ViewController {
171150 if ( section == 5 ) { return actions3. count }
172151 if ( section == 6 ) { return actions4. count }
173152 if ( section == 7 ) { return actions5. count }
174- if ( section == 8 ) { return alerticons. count }
175153
176154 return 0
177155 }
178156
179157 override func tableView( _ tableView: UITableView , cellForRowAt indexPath: IndexPath ) -> UITableViewCell {
180- if ( indexPath. section == 0 ) && ( indexPath. row == 0 ) { return self . tableView ( tableView, cellWithText: " Show Banner " ) }
181- if ( indexPath. section == 0 ) && ( indexPath. row == 1 ) { return self . tableView ( tableView, cellWithText: " Hide Banner " ) }
182-
183- if ( indexPath. section == 1 ) && ( indexPath. row == 0 ) { return cellText }
184- if ( indexPath. section == 1 ) && ( indexPath. row == 1 ) { return self . tableView ( tableView, cellWithText: " Dismiss Keyboard " ) }
185- if ( indexPath. section == 1 ) && ( indexPath. row == 2 ) { return self . tableView ( tableView, cellWithText: " Dismiss HUD " ) }
186- if ( indexPath. section == 1 ) && ( indexPath. row == 3 ) { return self . tableView ( tableView, cellWithText: " Remove HUD " ) }
187-
188- if ( indexPath. section == 2 ) { return self . tableView ( tableView, cellWithText: animations [ indexPath. row] . text) }
189- if ( indexPath. section == 3 ) { return self . tableView ( tableView, cellWithText: actions1 [ indexPath. row] ) }
190- if ( indexPath. section == 4 ) { return self . tableView ( tableView, cellWithText: actions2 [ indexPath. row] ) }
191- if ( indexPath. section == 5 ) { return self . tableView ( tableView, cellWithText: actions3 [ indexPath. row] ) }
192- if ( indexPath. section == 6 ) { return self . tableView ( tableView, cellWithText: actions4 [ indexPath. row] ) }
193- if ( indexPath. section == 7 ) { return self . tableView ( tableView, cellWithText: actions5 [ indexPath. row] ) }
194- if ( indexPath. section == 8 ) { return self . tableView ( tableView, cellWithText: alerticons [ indexPath. row] . text) }
158+ if ( indexPath. section == 0 ) && ( indexPath. row == 0 ) { return cellWithText ( tableView, " Show Banner " ) }
159+ if ( indexPath. section == 0 ) && ( indexPath. row == 1 ) { return cellWithText ( tableView, " Hide Banner " ) }
160+
161+ if ( indexPath. section == 1 ) && ( indexPath. row == 0 ) { return cellText }
162+ if ( indexPath. section == 1 ) && ( indexPath. row == 1 ) { return cellWithText ( tableView, " Dismiss Keyboard " ) }
163+ if ( indexPath. section == 1 ) && ( indexPath. row == 2 ) { return cellWithText ( tableView, " Dismiss HUD " ) }
164+ if ( indexPath. section == 1 ) && ( indexPath. row == 3 ) { return cellWithText ( tableView, " Remove HUD " ) }
165+
166+ if ( indexPath. section == 2 ) { return cellWithText ( tableView, animations [ indexPath. row] . text) }
167+ if ( indexPath. section == 3 ) { return cellWithText ( tableView, actions1 [ indexPath. row] ) }
168+ if ( indexPath. section == 4 ) { return cellWithText ( tableView, actions2 [ indexPath. row] ) }
169+ if ( indexPath. section == 5 ) { return cellWithText ( tableView, actions3 [ indexPath. row] ) }
170+ if ( indexPath. section == 6 ) { return cellWithText ( tableView, actions4 [ indexPath. row] ) }
171+ if ( indexPath. section == 7 ) { return cellWithText ( tableView, actions5 [ indexPath. row] ) }
195172
196173 return UITableViewCell ( )
197174 }
198175
199- func tableView ( _ tableView: UITableView , cellWithText text: String ) -> UITableViewCell {
176+ func cellWithText ( _ tableView: UITableView , _ text: String ) -> UITableViewCell {
200177 var cell : UITableViewCell ! = tableView. dequeueReusableCell ( withIdentifier: " cell " )
201178 if ( cell == nil ) { cell = UITableViewCell ( style: . default, reuseIdentifier: " cell " ) }
202179 cell. textLabel? . text = text
@@ -212,7 +189,6 @@ extension ViewController {
212189 if ( section == 5 ) { return " Progress " }
213190 if ( section == 6 ) { return " Action - Static " }
214191 if ( section == 7 ) { return " Action - Animated " }
215- if ( section == 8 ) { return " Alert Icons " }
216192 return nil
217193 }
218194}
@@ -259,10 +235,12 @@ extension ViewController {
259235 }
260236
261237 if ( indexPath. section == 6 ) {
262- if ( indexPath. row == 0 ) { ProgressHUD . showSuccess ( ) }
263- if ( indexPath. row == 1 ) { ProgressHUD . showSuccess ( textSuccess) }
264- if ( indexPath. row == 2 ) { ProgressHUD . showError ( ) }
265- if ( indexPath. row == 3 ) { ProgressHUD . showError ( textError) }
238+ if ( indexPath. row == 0 ) { ProgressHUD . show ( symbol: symbol ( ) ) }
239+ if ( indexPath. row == 1 ) { ProgressHUD . show ( textAdded, symbol: symbol ( ) ) }
240+ if ( indexPath. row == 2 ) { ProgressHUD . showSuccess ( ) }
241+ if ( indexPath. row == 3 ) { ProgressHUD . showSuccess ( textSuccess) }
242+ if ( indexPath. row == 4 ) { ProgressHUD . showError ( ) }
243+ if ( indexPath. row == 5 ) { ProgressHUD . showError ( textError) }
266244 }
267245
268246 if ( indexPath. section == 7 ) {
@@ -273,21 +251,26 @@ extension ViewController {
273251 if ( indexPath. row == 4 ) { ProgressHUD . showAdded ( ) }
274252 if ( indexPath. row == 5 ) { ProgressHUD . showAdded ( textAdded) }
275253 }
276-
277- if ( indexPath. section == 8 ) {
278- let alerticon = alerticons [ indexPath. row]
279- ProgressHUD . show ( randomText ( ) , icon: alerticon)
280- }
281254 }
282255}
283256
284- // MARK: - Text Methods
257+ // MARK: - Helper Methods
285258extension ViewController {
286259
287- func randomText( ) -> String ? {
288- let array = [ textShort, textLong, textSucceed, textFailed, textAdded, nil ]
289- let index = Int . random ( in: 0 ..< array. count)
290- return array [ index]
260+ func loadSymbols( ) {
261+ if let bundle = Bundle ( identifier: " com.apple.CoreGlyphs " ) {
262+ if let path = bundle. path ( forResource: " symbol_search " , ofType: " plist " ) {
263+ if let temp = NSDictionary ( contentsOfFile: path) {
264+ if let values = temp as? [ String : [ String ] ] {
265+ symbols = Array ( values. keys)
266+ }
267+ }
268+ }
269+ }
270+ }
271+
272+ func symbol( ) -> String {
273+ symbols. randomElement ( ) ?? " questionmark "
291274 }
292275
293276 func toggleText( ) -> String {
0 commit comments