Skip to content

Commit 6aede68

Browse files
author
pera
authored
Merge pull request #371 from xmartlabs/feature/swiftlint
Add swiftlint & fixes
2 parents a0c75eb + 0b7dc7f commit 6aede68

33 files changed

+506
-514
lines changed

.swiftlint.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
disabled_rules: # rule identifiers to exclude from running
2+
# - colon
3+
# - comma
4+
# - control_statement
5+
- line_length
6+
- function_body_length
7+
- identifier_name
8+
- type_name
9+
- large_tuple
10+
opt_in_rules: # some rules are only opt-in
11+
- empty_count
12+
# Find all the available rules by running:
13+
# swiftlint rules
14+
excluded: # paths to ignore during linting. Takes precedence over `included`.
15+
- Carthage
16+
- Pods
17+
- Source/ExcludedFolder
18+
- Source/ExcludedFile.swift
19+
20+
# configurable rules can be customized from this configuration file
21+
# binary rules can set their severity level
22+
force_cast: warning # implicitly
23+
force_try:
24+
severity: warning # explicitly
25+
# rules that have both warning and error levels, can set just the warning level
26+
# implicitly
27+
line_length: 200
28+
# they can set both implicitly with an array
29+
type_body_length:
30+
- 300 # warning
31+
- 400 # error
32+
# or they can set both explicitly
33+
file_length:
34+
warning: 500
35+
error: 1200
36+
# naming rules can set warnings/errors for min_length and max_length
37+
# additionally they can set excluded names
38+
type_name:
39+
min_length: 4 # only warning
40+
max_length: # warning and error
41+
warning: 40
42+
error: 50
43+
excluded: iPhone # excluded via string
44+
identifier_name:
45+
min_length: # only min_length
46+
error: 4 # only error
47+
excluded: # excluded via string array
48+
- id
49+
- URL
50+
- GlobalAPIKey
51+
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji)

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: objective-c
2-
osx_image: xcode8
2+
osx_image: xcode8.3
33
env:
4-
- DESTINATION="OS=10.0,name=iPhone 6s" SCHEME="XLPagerTabStrip" SDK=iphonesimulator10.0
4+
- DESTINATION="OS=10.3,name=iPhone 6s" SCHEME="XLPagerTabStrip" SDK=iphonesimulator10.3
55
before_install:
66
- brew update
77
#- brew outdated carthage || brew upgrade carthage

Example/Example/AppDelegate.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1212

1313
var window: UIWindow?
1414

15-
1615
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1716
// Override point for customization after application launch.
18-
17+
1918
UITabBar.appearance().tintColor = UIColor.init(red: 0.027, green: 0.725, blue: 0.608, alpha: 1)
2019
UIApplication.shared.statusBarStyle = .lightContent
21-
22-
let _ = YoutubeExampleViewController(nibName: nil, bundle: nil)
23-
20+
21+
_ = YoutubeExampleViewController(nibName: nil, bundle: nil)
22+
2423
return true
2524
}
2625

@@ -46,6 +45,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4645
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
4746
}
4847

49-
5048
}
51-

Example/Example/BarExampleViewController.swift

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,51 +27,50 @@ import XLPagerTabStrip
2727

2828
class BarExampleViewController: BarPagerTabStripViewController {
2929
var isReload = false
30-
30+
3131
required init?(coder aDecoder: NSCoder) {
3232
super.init(coder: aDecoder)
3333
}
34-
34+
3535
override func viewDidLoad() {
36-
36+
3737
// set up style before super view did load is executed
3838
settings.style.selectedBarBackgroundColor = .orange
3939
// -
40-
40+
4141
super.viewDidLoad()
4242
}
43-
43+
4444
// MARK: - PagerTabStripDataSource
45-
45+
4646
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
47-
47+
4848
let child_1 = TableChildExampleViewController(style: .plain, itemInfo: "Table View")
4949
let child_2 = ChildExampleViewController(itemInfo: "View")
5050
let child_3 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 2")
5151
let child_4 = ChildExampleViewController(itemInfo: "View 2")
52-
52+
5353
guard isReload else {
5454
return [child_1, child_2, child_3, child_4]
5555
}
56-
56+
5757
var childViewControllers = [child_1, child_2, child_3, child_4]
58-
for (index, _) in childViewControllers.enumerated(){
58+
for index in childViewControllers.indices {
5959
let nElements = childViewControllers.count - index
6060
let n = (Int(arc4random()) % nElements) + index
61-
if n != index{
61+
if n != index {
6262
swap(&childViewControllers[index], &childViewControllers[n])
6363
}
6464
}
6565
let nItems = 1 + (arc4random() % 4)
6666
return Array(childViewControllers.prefix(Int(nItems)))
6767
}
68-
68+
6969
override func reloadPagerTabStripView() {
7070
isReload = true
7171
if arc4random() % 2 == 0 {
7272
pagerBehaviour = .progressive(skipIntermediateViewControllers: arc4random() % 2 == 0, elasticIndicatorLimit: arc4random() % 2 == 0 )
73-
}
74-
else {
73+
} else {
7574
pagerBehaviour = .common(skipIntermediateViewControllers: arc4random() % 2 == 0)
7675
}
7776
super.reloadPagerTabStripView()

Example/Example/ButtonBarExampleViewController.swift

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ import Foundation
2626
import XLPagerTabStrip
2727

2828
class ButtonBarExampleViewController: ButtonBarPagerTabStripViewController {
29-
29+
3030
var isReload = false
31-
31+
3232
override func viewDidLoad() {
3333
super.viewDidLoad()
34-
34+
3535
buttonBarView.selectedBar.backgroundColor = .orange
3636
buttonBarView.backgroundColor = UIColor(red: 7/255, green: 185/255, blue: 155/255, alpha: 1)
3737
}
38-
38+
3939
// MARK: - PagerTabStripDataSource
40-
40+
4141
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
4242
let child_1 = TableChildExampleViewController(style: .plain, itemInfo: "Table View")
4343
let child_2 = ChildExampleViewController(itemInfo: "View")
@@ -47,30 +47,29 @@ class ButtonBarExampleViewController: ButtonBarPagerTabStripViewController {
4747
let child_6 = ChildExampleViewController(itemInfo: "View 3")
4848
let child_7 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 4")
4949
let child_8 = ChildExampleViewController(itemInfo: "View 4")
50-
50+
5151
guard isReload else {
5252
return [child_1, child_2, child_3, child_4, child_5, child_6, child_7, child_8]
5353
}
54-
54+
5555
var childViewControllers = [child_1, child_2, child_3, child_4, child_6, child_7, child_8]
56-
57-
for (index, _) in childViewControllers.enumerated(){
56+
57+
for index in childViewControllers.indices {
5858
let nElements = childViewControllers.count - index
5959
let n = (Int(arc4random()) % nElements) + index
60-
if n != index{
60+
if n != index {
6161
swap(&childViewControllers[index], &childViewControllers[n])
6262
}
6363
}
6464
let nItems = 1 + (arc4random() % 8)
6565
return Array(childViewControllers.prefix(Int(nItems)))
6666
}
67-
67+
6868
override func reloadPagerTabStripView() {
6969
isReload = true
7070
if arc4random() % 2 == 0 {
7171
pagerBehaviour = .progressive(skipIntermediateViewControllers: arc4random() % 2 == 0, elasticIndicatorLimit: arc4random() % 2 == 0 )
72-
}
73-
else {
72+
} else {
7473
pagerBehaviour = .common(skipIntermediateViewControllers: arc4random() % 2 == 0)
7574
}
7675
super.reloadPagerTabStripView()

Example/Example/ChildControllers/ChildExampleViewController.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import Foundation
2626
import XLPagerTabStrip
2727

2828
class ChildExampleViewController: UIViewController, IndicatorInfoProvider {
29-
29+
3030
var itemInfo: IndicatorInfo = "View"
31-
31+
3232
init(itemInfo: IndicatorInfo) {
3333
self.itemInfo = itemInfo
3434
super.init(nibName: nil, bundle: nil)
@@ -37,23 +37,23 @@ class ChildExampleViewController: UIViewController, IndicatorInfoProvider {
3737
required init?(coder aDecoder: NSCoder) {
3838
fatalError("init(coder:) has not been implemented")
3939
}
40-
40+
4141
override func viewDidLoad() {
4242
super.viewDidLoad()
43-
43+
4444
let label = UILabel()
4545
label.translatesAutoresizingMaskIntoConstraints = false
4646
label.text = "XLPagerTabStrip"
47-
47+
4848
view.addSubview(label)
4949
view.backgroundColor = .white
50-
50+
5151
view.addConstraint(NSLayoutConstraint(item: label, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1, constant: 0))
5252
view.addConstraint(NSLayoutConstraint(item: label, attribute: .centerY, relatedBy: .equal, toItem: view, attribute: .centerY, multiplier: 1, constant: -50))
5353
}
54-
54+
5555
// MARK: - IndicatorInfoProvider
56-
56+
5757
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
5858
return itemInfo
5959
}

Example/Example/ChildControllers/TableChildExampleViewController.swift

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,60 +26,61 @@ import Foundation
2626
import XLPagerTabStrip
2727

2828
class TableChildExampleViewController: UITableViewController, IndicatorInfoProvider {
29-
29+
3030
let cellIdentifier = "postCell"
3131
var blackTheme = false
3232
var itemInfo = IndicatorInfo(title: "View")
33-
33+
3434
init(style: UITableViewStyle, itemInfo: IndicatorInfo) {
3535
self.itemInfo = itemInfo
3636
super.init(style: style)
3737
}
38-
38+
3939
required init?(coder aDecoder: NSCoder) {
4040
fatalError("init(coder:) has not been implemented")
4141
}
42-
42+
4343
override func viewDidLoad() {
4444
super.viewDidLoad()
4545
tableView.register(UINib(nibName: "PostCell", bundle: Bundle.main), forCellReuseIdentifier: cellIdentifier)
46-
tableView.estimatedRowHeight = 60.0;
46+
tableView.estimatedRowHeight = 60.0
4747
tableView.rowHeight = UITableViewAutomaticDimension
4848
tableView.allowsSelection = false
4949
if blackTheme {
5050
tableView.backgroundColor = UIColor(red: 15/255.0, green: 16/255.0, blue: 16/255.0, alpha: 1.0)
5151
}
5252
}
53-
53+
5454
override func viewWillAppear(_ animated: Bool) {
5555
super.viewWillAppear(animated)
5656
tableView.reloadData()
5757
}
58-
58+
5959
// MARK: - UITableViewDataSource
60-
60+
6161
override func numberOfSections(in tableView: UITableView) -> Int {
6262
return 1
6363
}
64-
64+
6565
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
6666
return DataProvider.sharedInstance.postsData.count
6767
}
6868

6969
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
70-
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! PostCell
71-
let data = DataProvider.sharedInstance.postsData.object(at: indexPath.row) as!
72-
NSDictionary
70+
guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? PostCell,
71+
let data = DataProvider.sharedInstance.postsData.object(at: indexPath.row) as? NSDictionary else { return PostCell() }
72+
7373
cell.configureWithData(data)
7474
if blackTheme {
7575
cell.changeStylToBlack()
7676
}
7777
return cell
7878
}
79-
79+
8080
// MARK: - IndicatorInfoProvider
8181

8282
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
8383
return itemInfo
8484
}
85+
8586
}

Example/Example/Helpers/DataProvider.swift

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,27 @@ import UIKit
2727

2828
class DataProvider {
2929
static let sharedInstance = DataProvider()
30-
30+
3131
lazy var postsData: NSArray = {
3232
let jsonStr = "[{\"post\":{\"id\":113,\"text\":\"We're getting fifty percent of the t-shirt sales\",\"created_at\":\"2014-04-17T00:45:40.556Z\",\"user\":{\"id\":9,\"name\":\"Lisa Simpsons\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Lisa_Simpsons.png\"}}},{\"post\":{\"id\":66,\"text\":\"Eep!\",\"created_at\":\"2014-04-09T21:29:59.982Z\",\"user\":{\"id\":7,\"name\":\"Bart Simpsons\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Bart_Simpsons.png\"}}},{\"post\":{\"id\":42,\"text\":\"I'm not thinking straight, why did I have that wine cooler last month?\",\"created_at\":\"2014-04-09T17:58:41.704Z\",\"user\":{\"id\":5,\"name\":\"Ned Flanders\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Ned_Flanders.png\"}}},{\"post\":{\"id\":84,\"text\":\"Son, when you participate in sporting events, it's not whether you win or lose: it's how drunk you get.\",\"created_at\":\"2014-04-03T20:21:32.119Z\",\"user\":{\"id\":8,\"name\":\"Homer Simpsons\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Homer_Simpsons.png\"}}},{\"post\":{\"id\":75,\"text\":\"I'm normally not a praying man, but if you're up there, please save me Superman.\",\"created_at\":\"2014-04-03T02:04:43.053Z\",\"user\":{\"id\":8,\"name\":\"Homer Simpsons\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Homer_Simpsons.png\"}}},{\"post\":{\"id\":26,\"text\":\"Homer, please get rid of that pig.\",\"created_at\":\"2014-04-02T03:48:56.381Z\",\"user\":{\"id\":3,\"name\":\"Marge Simpsons\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Marge_Simpsons.png\"}}},{\"post\":{\"id\":40,\"text\":\"You sold weapon-grade plutoneum to the Iraqies without a mark up.\",\"created_at\":\"2014-03-28T05:23:24.657Z\",\"user\":{\"id\":4,\"name\":\"Montgomery Burns\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Montgomery_Burns.png\"}}},{\"post\":{\"id\":28,\"text\":\"Homer, don't say that. The way I see it, if you raised three children who can knock out and hog tie a perfect stranger you must be doing something right.\",\"created_at\":\"2014-03-22T14:24:22.408Z\",\"user\":{\"id\":3,\"name\":\"Marge Simpsons\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Marge_Simpsons.png\"}}},{\"post\":{\"id\":48,\"text\":\"Hi-dilly-ho, neighborinos!\",\"created_at\":\"2014-03-21T08:39:20.764Z\",\"user\":{\"id\":5,\"name\":\"Ned Flanders\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Ned_Flanders.png\"}}},{\"post\":{\"id\":78,\"text\":\"Maybe, just once, someone will call me 'Sir' without adding, 'You're making a scene.'\",\"created_at\":\"2014-03-20T02:44:28.075Z\",\"user\":{\"id\":8,\"name\":\"Homer Simpsons\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Homer_Simpsons.png\"}}},{\"post\":{\"id\":33,\"text\":\"This is the type of trickery I pay you for.\",\"created_at\":\"2014-03-18T08:25:14.507Z\",\"user\":{\"id\":4,\"name\":\"Montgomery Burns\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Montgomery_Burns.png\"}}},{\"post\":{\"id\":72,\"text\":\"Oh, so they have internet on computers now!\",\"created_at\":\"2014-03-03T19:02:56.032Z\",\"user\":{\"id\":8,\"name\":\"Homer Simpsons\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Homer_Simpsons.png\"}}},{\"post\":{\"id\":1,\"text\":\"You know, I do! I mean, there comes a time in a man's life when he asks himself, 'who will float my corpse down the Ganges?'\",\"created_at\":\"2014-02-24T14:09:00.912Z\",\"user\":{\"id\":1,\"name\":\"Apu Nahasapeemapetilon\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Apu_Nahasapeemapetilon.png\"}}},{\"post\":{\"id\":62,\"text\":\"Ay Caramba!\",\"created_at\":\"2014-02-18T16:38:37.958Z\",\"user\":{\"id\":7,\"name\":\"Bart Simpsons\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Bart_Simpsons.png\"}}},{\"post\":{\"id\":19,\"text\":\"Throughout the ages, the finger painter, the Play-Doh sculptor, the Lincoln Logger, stood alone against the daycare teacher of her time. She did not live to earn aproval stickers, she lived for herself, that she might achieve things that are the glory of all humanity. These are my terms. I do not care to play by any others. And now, if the jury will allow me, it's naptime.\",\"created_at\":\"2014-02-16T22:11:33.236Z\",\"user\":{\"id\":2,\"name\":\"Maggie Simpsons\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Maggie_Simpsons.png\"}}},{\"post\":{\"id\":76,\"text\":\"Son, if you really want something in this life, you have to work for it. Now quiet! They're about to announce the lottery numbers.\",\"created_at\":\"2014-02-16T19:09:55.062Z\",\"user\":{\"id\":8,\"name\":\"Homer Simpsons\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Homer_Simpsons.png\"}}},{\"post\":{\"id\":22,\"text\":\"Somebody throw the goddamn bomb!\",\"created_at\":\"2014-02-16T13:50:25.313Z\",\"user\":{\"id\":3,\"name\":\"Marge Simpsons\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Marge_Simpsons.png\"}}},{\"post\":{\"id\":36,\"text\":\"Oh, so mother nature needs a favor? Well, maybe she should have thought of that when she was besetting us with droughts and floods and poison monkeys.\",\"created_at\":\"2014-02-13T06:51:57.549Z\",\"user\":{\"id\":4,\"name\":\"Montgomery Burns\",\"imageURL\":\"http://obscure-refuge-3149.herokuapp.com/images/Montgomery_Burns.png\"}}}]"
3333
let jsonData = jsonStr.data(using: String.Encoding.utf8)
34-
return try! JSONSerialization.jsonObject(with: jsonData!, options: []) as! NSArray
34+
let res = try! JSONSerialization.jsonObject(with: jsonData!, options: []) // swiftlint:disable:this force_try
35+
return res as! NSArray // swiftlint:disable:this force_cast
3536
}()
3637
}
3738

3839
class NavController: UINavigationController {
39-
40-
41-
override var preferredStatusBarStyle : UIStatusBarStyle {
40+
41+
override var preferredStatusBarStyle: UIStatusBarStyle {
4242
return .lightContent
4343
}
44-
44+
4545
}
4646

47+
class TabBarController: UITabBarController {
4748

48-
class TabBarController : UITabBarController {
49-
50-
override var preferredStatusBarStyle : UIStatusBarStyle {
49+
override var preferredStatusBarStyle: UIStatusBarStyle {
5150
return .lightContent
5251
}
53-
54-
}
55-
56-
57-
58-
5952

53+
}

0 commit comments

Comments
 (0)