Skip to content

Commit 35c33bf

Browse files
authored
Merge pull request #24 from yacir/swiftlint
Fix SwiftLint errors & warnings
2 parents 6dba41a + 5de065b commit 35c33bf

7 files changed

Lines changed: 100 additions & 101 deletions

File tree

Examples/CollectionViewSlantedLayoutDemo.xcodeproj/project.pbxproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
FB1735891C83A0B400EEDB5F /* Resources */,
139139
FB132C761C91135E00728981 /* CopyFiles */,
140140
6DF225E9B9A30B644E491F10 /* [CP] Embed Pods Frameworks */,
141+
FB3A7BDF215F4DEF00B18AE8 /* SwiftLint */,
141142
);
142143
buildRules = (
143144
);
@@ -233,6 +234,24 @@
233234
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CollectionViewSlantedLayoutDemo/Pods-CollectionViewSlantedLayoutDemo-frameworks.sh\"\n";
234235
showEnvVarsInLog = 0;
235236
};
237+
FB3A7BDF215F4DEF00B18AE8 /* SwiftLint */ = {
238+
isa = PBXShellScriptBuildPhase;
239+
buildActionMask = 2147483647;
240+
files = (
241+
);
242+
inputFileListPaths = (
243+
);
244+
inputPaths = (
245+
);
246+
name = SwiftLint;
247+
outputFileListPaths = (
248+
);
249+
outputPaths = (
250+
);
251+
runOnlyForDeploymentPostprocessing = 0;
252+
shellPath = /bin/sh;
253+
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
254+
};
236255
/* End PBXShellScriptBuildPhase section */
237256

238257
/* Begin PBXSourcesBuildPhase section */

Examples/CollectionViewSlantedLayoutDemo/AppDelegate.swift

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313

1414
var window: UIWindow?
1515

16-
17-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
16+
func application(_ application: UIApplication,
17+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
1818
// Override point for customization after application launch.
1919
return true
2020
}
2121

22-
func applicationWillResignActive(_ application: UIApplication) {
23-
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24-
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25-
}
26-
27-
func applicationDidEnterBackground(_ application: UIApplication) {
28-
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30-
}
31-
32-
func applicationWillEnterForeground(_ application: UIApplication) {
33-
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34-
}
35-
36-
func applicationDidBecomeActive(_ application: UIApplication) {
37-
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38-
}
39-
40-
func applicationWillTerminate(_ application: UIApplication) {
41-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42-
}
43-
44-
4522
}
46-

Examples/CollectionViewSlantedLayoutDemo/CustomCollectionCell.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,43 @@ let yOffsetSpeed: CGFloat = 150.0
1616
let xOffsetSpeed: CGFloat = 100.0
1717

1818
class CustomCollectionCell: CollectionViewSlantedCell {
19-
19+
2020
@IBOutlet weak var imageView: UIImageView!
2121
private var gradient = CAGradientLayer()
22-
22+
2323
override func awakeFromNib() {
2424
super.awakeFromNib()
25-
25+
2626
if let backgroundView = backgroundView {
2727
gradient.colors = [UIColor.clear.cgColor, UIColor.black.cgColor]
2828
gradient.locations = [0.0, 1.0]
2929
gradient.frame = backgroundView.bounds
3030
backgroundView.layer.addSublayer(gradient)
3131
}
3232
}
33-
33+
3434
override func layoutSubviews() {
3535
super.layoutSubviews()
3636
if let backgroundView = backgroundView {
3737
gradient.frame = backgroundView.bounds
3838
}
3939
}
40-
40+
4141
var image: UIImage = UIImage() {
4242
didSet {
4343
imageView.image = image
4444
}
4545
}
46-
46+
4747
var imageHeight: CGFloat {
4848
return (imageView?.image?.size.height) ?? 0.0
4949
}
50-
50+
5151
var imageWidth: CGFloat {
5252
return (imageView?.image?.size.width) ?? 0.0
5353
}
5454

55-
5655
func offset(_ offset: CGPoint) {
57-
imageView.frame = self.imageView.bounds.offsetBy(dx: offset.x, dy: offset.y)
56+
imageView.frame = imageView.bounds.offsetBy(dx: offset.x, dy: offset.y)
5857
}
5958
}

Examples/CollectionViewSlantedLayoutDemo/SettingsController.swift

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,68 +13,68 @@ import UIKit
1313
import CollectionViewSlantedLayout
1414

1515
class SettingsController: UITableViewController {
16-
16+
1717
weak var collectionViewLayout: CollectionViewSlantedLayout!
18-
18+
1919
@IBOutlet weak var slantingDirectionSegment: UISegmentedControl!
2020
@IBOutlet weak var scrollDirectionSegment: UISegmentedControl!
2121
@IBOutlet weak var zIndexOrderSegment: UISegmentedControl!
2222
@IBOutlet weak var firstCellSlantingSwitch: UISwitch!
2323
@IBOutlet weak var lastCellSlantingSwitch: UISwitch!
2424
@IBOutlet weak var slantingSizeSlider: UISlider!
2525
@IBOutlet weak var lineSpacingSlider: UISlider!
26-
26+
2727
override func viewDidLoad() {
2828
super.viewDidLoad()
29-
30-
self.slantingDirectionSegment.selectedSegmentIndex = (self.collectionViewLayout.slantingDirection == .downward) ? 0 : 1
31-
self.scrollDirectionSegment.selectedSegmentIndex = (self.collectionViewLayout.scrollDirection == .horizontal) ? 0 : 1
32-
self.zIndexOrderSegment.selectedSegmentIndex = (self.collectionViewLayout.zIndexOrder == .descending) ? 0 : 1
33-
self.firstCellSlantingSwitch.isOn = self.collectionViewLayout.isFirstCellExcluded
34-
self.lastCellSlantingSwitch.isOn = self.collectionViewLayout.isLastCellExcluded
35-
self.slantingSizeSlider.value = Float(self.collectionViewLayout.slantingSize)
36-
self.lineSpacingSlider.value = Float(self.collectionViewLayout.lineSpacing)
29+
30+
slantingDirectionSegment.selectedSegmentIndex = (collectionViewLayout.slantingDirection == .downward) ? 0 : 1
31+
scrollDirectionSegment.selectedSegmentIndex = (collectionViewLayout.scrollDirection == .horizontal) ? 0 : 1
32+
zIndexOrderSegment.selectedSegmentIndex = (collectionViewLayout.zIndexOrder == .descending) ? 0 : 1
33+
firstCellSlantingSwitch.isOn = collectionViewLayout.isFirstCellExcluded
34+
lastCellSlantingSwitch.isOn = collectionViewLayout.isLastCellExcluded
35+
slantingSizeSlider.value = Float(collectionViewLayout.slantingSize)
36+
lineSpacingSlider.value = Float(collectionViewLayout.lineSpacing)
3737
}
38-
39-
override var prefersStatusBarHidden : Bool {
38+
39+
override var prefersStatusBarHidden: Bool {
4040
return false
4141
}
42-
43-
override var preferredStatusBarUpdateAnimation : UIStatusBarAnimation {
42+
43+
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
4444
return UIStatusBarAnimation.slide
4545
}
46-
46+
4747
@IBAction func slantingDirectionChanged(_ sender: UISegmentedControl) {
48-
self.collectionViewLayout.slantingDirection = (sender.selectedSegmentIndex == 0 ? .downward : .upward )
48+
collectionViewLayout.slantingDirection = (sender.selectedSegmentIndex == 0 ? .downward : .upward )
4949
}
50-
50+
5151
@IBAction func scrollDirectionChanged(_ sender: UISegmentedControl) {
52-
self.collectionViewLayout.scrollDirection = (sender.selectedSegmentIndex == 0 ? .horizontal : .vertical)
52+
collectionViewLayout.scrollDirection = (sender.selectedSegmentIndex == 0 ? .horizontal : .vertical)
5353
}
5454

5555
@IBAction func zIndexOrderChanged(_ sender: UISegmentedControl) {
56-
self.collectionViewLayout.zIndexOrder = (sender.selectedSegmentIndex == 0 ? .descending : .ascending)
56+
collectionViewLayout.zIndexOrder = (sender.selectedSegmentIndex == 0 ? .descending : .ascending)
5757
}
5858

5959
@IBAction func firstCellSlantingSwitchChanged(_ sender: UISwitch) {
60-
self.collectionViewLayout.isFirstCellExcluded = sender.isOn
60+
collectionViewLayout.isFirstCellExcluded = sender.isOn
6161
}
62-
62+
6363
@IBAction func lastCellSlantingSwitchChanged(_ sender: UISwitch) {
64-
self.collectionViewLayout.isLastCellExcluded = sender.isOn
64+
collectionViewLayout.isLastCellExcluded = sender.isOn
6565
}
66-
66+
6767
@IBAction func slantingSizeChanged(_ sender: UISlider) {
68-
self.collectionViewLayout.slantingSize = UInt(sender.value)
68+
collectionViewLayout.slantingSize = UInt(sender.value)
6969
}
70-
70+
7171
@IBAction func lineSpacingChanged(_ sender: UISlider) {
72-
self.collectionViewLayout.lineSpacing = CGFloat(sender.value)
72+
collectionViewLayout.lineSpacing = CGFloat(sender.value)
7373
}
7474
@IBAction func done(_ sender: AnyObject) {
75-
self.presentingViewController?.dismiss(animated: true, completion: { () -> Void in
76-
self.collectionViewLayout.collectionView?.scrollRectToVisible(CGRect(x: 0, y: 0, width: 0, height: 0), animated: true);
75+
presentingViewController?.dismiss(animated: true, completion: { [weak self] () -> Void in
76+
let rect = CGRect(x: 0, y: 0, width: 0, height: 0)
77+
self?.collectionViewLayout.collectionView?.scrollRectToVisible(rect, animated: true)
7778
})
7879
}
7980
}
80-

Examples/CollectionViewSlantedLayoutDemo/ViewController.swift

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,74 +15,80 @@ class ViewController: UIViewController {
1515
@IBOutlet weak var collectionView: UICollectionView!
1616
@IBOutlet weak var collectionViewLayout: CollectionViewSlantedLayout!
1717

18-
internal var covers = [[String:String]]()
18+
internal var covers = [[String: String]]()
1919

2020
let reuseIdentifier = "customViewCell"
21-
21+
2222
override func loadView() {
2323
super.loadView()
24-
if let url = Bundle.main.url(forResource: "covers", withExtension: "plist") {
25-
covers = (NSArray(contentsOf: url) as! [[String:String]])
24+
if let url = Bundle.main.url(forResource: "covers", withExtension: "plist"),
25+
let contents = NSArray(contentsOf: url) as? [[String: String]] {
26+
covers = contents
2627
}
2728
}
28-
29+
2930
override func viewDidLoad() {
3031
super.viewDidLoad()
31-
self.navigationController?.isNavigationBarHidden = true
32+
navigationController?.isNavigationBarHidden = true
3233
collectionViewLayout.isFirstCellExcluded = true
3334
collectionViewLayout.isLastCellExcluded = true
3435
}
35-
36+
3637
override func viewWillAppear(_ animated: Bool) {
3738
super.viewWillAppear(animated)
38-
self.collectionView.reloadData()
39-
self.collectionView.collectionViewLayout.invalidateLayout()
39+
collectionView.reloadData()
40+
collectionView.collectionViewLayout.invalidateLayout()
4041
}
41-
42-
override var prefersStatusBarHidden : Bool {
42+
43+
override var prefersStatusBarHidden: Bool {
4344
return true
4445
}
45-
46-
override var preferredStatusBarUpdateAnimation : UIStatusBarAnimation {
46+
47+
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
4748
return UIStatusBarAnimation.slide
4849
}
49-
50+
5051
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
51-
if segue.identifier == "ShowSettings" {
52-
let settingsController = segue.destination as! SettingsController
53-
let layout = collectionView.collectionViewLayout as! CollectionViewSlantedLayout
54-
settingsController.collectionViewLayout = layout
52+
guard segue.identifier == "ShowSettings" ,
53+
let settingsController = segue.destination as? SettingsController,
54+
let layout = collectionView.collectionViewLayout as? CollectionViewSlantedLayout else {
55+
return
5556
}
57+
58+
settingsController.collectionViewLayout = layout
5659
}
5760
}
5861

5962
extension ViewController: UICollectionViewDataSource {
60-
63+
6164
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
6265
return covers.count
6366
}
64-
67+
6568
func collectionView(_ collectionView: UICollectionView,
66-
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
69+
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
70+
71+
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)
72+
as? CustomCollectionCell else {
73+
fatalError()
74+
}
6775

68-
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! CustomCollectionCell
69-
7076
cell.image = UIImage(named: covers[indexPath.row]["picture"]!)!
7177

7278
if let layout = collectionView.collectionViewLayout as? CollectionViewSlantedLayout {
7379
cell.contentView.transform = CGAffineTransform(rotationAngle: layout.slantingAngle)
7480
}
75-
81+
7682
return cell
7783
}
7884
}
7985

8086
extension ViewController: CollectionViewDelegateSlantedLayout {
81-
87+
8288
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
8389
NSLog("Did select item at indexPath: [\(indexPath.section)][\(indexPath.row)]")
8490
}
85-
91+
8692
func collectionView(_ collectionView: UICollectionView,
8793
layout collectionViewLayout: CollectionViewSlantedLayout,
8894
sizeForItemAt indexPath: IndexPath) -> CGFloat {
@@ -92,13 +98,12 @@ extension ViewController: CollectionViewDelegateSlantedLayout {
9298

9399
extension ViewController: UIScrollViewDelegate {
94100
func scrollViewDidScroll(_ scrollView: UIScrollView) {
95-
guard let collectionView = self.collectionView else {return}
101+
guard let collectionView = collectionView else {return}
96102
guard let visibleCells = collectionView.visibleCells as? [CustomCollectionCell] else {return}
97103
for parallaxCell in visibleCells {
98-
let yOffset = ((collectionView.contentOffset.y - parallaxCell.frame.origin.y) / parallaxCell.imageHeight) * yOffsetSpeed
99-
let xOffset = ((collectionView.contentOffset.x - parallaxCell.frame.origin.x) / parallaxCell.imageWidth) * xOffsetSpeed
100-
parallaxCell.offset(CGPoint(x: xOffset,y :yOffset))
104+
let yOffset = (collectionView.contentOffset.y - parallaxCell.frame.origin.y) / parallaxCell.imageHeight
105+
let xOffset = (collectionView.contentOffset.x - parallaxCell.frame.origin.x) / parallaxCell.imageWidth
106+
parallaxCell.offset(CGPoint(x: xOffset * xOffsetSpeed, y: yOffset * yOffsetSpeed))
101107
}
102108
}
103109
}
104-

Sources/CollectionViewSlantedCell.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import UIKit
3535

3636
/// :nodoc:
3737
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
38-
guard let mask = self.slantedLayerMask else {
38+
guard let mask = slantedLayerMask else {
3939
return super.point(inside: point, with: event)
4040
}
4141

@@ -51,7 +51,7 @@ import UIKit
5151
guard let layoutAttributes = layoutAttributes as? CollectionViewSlantedLayoutAttributes else {
5252
return
5353
}
54-
self.slantedLayerMask = layoutAttributes.slantedLayerMask
55-
self.layer.mask = layoutAttributes.slantedLayerMask
54+
slantedLayerMask = layoutAttributes.slantedLayerMask
55+
layer.mask = layoutAttributes.slantedLayerMask
5656
}
5757
}

Sources/Internal/CollectionViewSlantedLayoutAttributes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ open class CollectionViewSlantedLayoutAttributes: UICollectionViewLayoutAttribut
3535

3636
let attributesCopy = super.copy(with: zone)
3737
if let attributesCopy = attributesCopy as? CollectionViewSlantedLayoutAttributes {
38-
attributesCopy.slantedLayerMask = self.slantedLayerMask
38+
attributesCopy.slantedLayerMask = slantedLayerMask
3939
}
4040
return attributesCopy
4141
}
@@ -44,7 +44,7 @@ open class CollectionViewSlantedLayoutAttributes: UICollectionViewLayoutAttribut
4444
override open func isEqual(_ object: Any?) -> Bool {
4545

4646
if let obj = object as? CollectionViewSlantedLayoutAttributes {
47-
if self.slantedLayerMask != obj.slantedLayerMask {
47+
if slantedLayerMask != obj.slantedLayerMask {
4848
return false
4949
}
5050
return super.isEqual(object)

0 commit comments

Comments
 (0)