Skip to content

Commit

Permalink
Merge pull request #13 from TheNounProject/SwiftLint
Browse files Browse the repository at this point in the history
SwiftLint
  • Loading branch information
WCByrne authored Aug 13, 2018
2 parents 027ffed + 41b978f commit 3a32809
Show file tree
Hide file tree
Showing 67 changed files with 1,473 additions and 2,271 deletions.
48 changes: 48 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
disabled_rules:
- trailing_whitespace
- identifier_name
- statement_position
- large_tuple
- force_cast
- force_try
- type_name
- function_parameter_count
- cyclomatic_complexity
- operator_whitespace
- private_over_fileprivate
- nesting
- type_body_length
- multiple_closures_with_trailing_closure
- notification_center_detachment
opt_in_rules:
- empty_count
- empty_string
excluded:
- Carthage
- Pods
- Example
- SwiftLint/Common/3rdPartyLib
line_length:
warning: 150
error: 200
ignores_function_declarations: true
ignores_comments: true
ignores_urls: true
ignores_interpolated_strings: true
function_body_length:
warning: 300
error: 500
function_parameter_count:
warning: 6
error: 8
type_body_length:
warning: 300
error: 500
file_length:
warning: 1000
error: 1500
ignore_comment_only_lines: true
cyclomatic_complexity:
warning: 20
error: 25
reporter: "xcode"
22 changes: 22 additions & 0 deletions CollectionView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
DE9071E51CAC7FD800AD0E37 /* Frameworks */,
DE9071E61CAC7FD800AD0E37 /* Headers */,
DE9071E71CAC7FD800AD0E37 /* Resources */,
1CB6A657211D6BAC00907CEF /* SwiftLint */,
);
buildRules = (
);
Expand Down Expand Up @@ -377,6 +378,27 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
1CB6A657211D6BAC00907CEF /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = SwiftLint;
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
DE9071E41CAC7FD800AD0E37 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
55 changes: 23 additions & 32 deletions CollectionView/ClipView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@
//import Foundation
import AppKit


//typealias DisplayLinkCallback = @convention(block) ( CVDisplayLink!, UnsafePointer<CVTimeStamp>, UnsafePointer<CVTimeStamp>, CVOptionFlags, UnsafeMutablePointer<CVOptionFlags>, UnsafeMutablePointer<Void>)->Void

open class ClipView : NSClipView {
open class ClipView: NSClipView {

static let DefaultDecelerationRate : CGFloat = 0.78
static let DefaultDecelerationRate: CGFloat = 0.78

var shouldAnimateOriginChange = false
var destinationOrigin = CGPoint.zero
var scrollView : NSScrollView? { return self.enclosingScrollView ?? self.superview as? NSScrollView }

var scrollEnabled : Bool = true

var scrollView: NSScrollView? { return self.enclosingScrollView ?? self.superview as? NSScrollView }

var scrollEnabled: Bool = true

/**
The rate of deceleration for animated scrolls. Higher is slower. default is 0.78
Expand All @@ -34,7 +31,7 @@ open class ClipView : NSClipView {
}
}

var completionBlock : AnimationCompletion?
var completionBlock: AnimationCompletion?

init(clipView: NSClipView) {
super.init(frame: clipView.frame)
Expand All @@ -47,7 +44,6 @@ open class ClipView : NSClipView {
NotificationCenter.default.removeObserver(self)
}


override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
self.setup()
Expand All @@ -64,12 +60,15 @@ open class ClipView : NSClipView {
}

override open func viewWillMove(toWindow newWindow: NSWindow?) {
if (self.window != nil) {
NotificationCenter.default.removeObserver(self, name: NSWindow.didChangeScreenNotification, object: self.window)
if self.window != nil {
NotificationCenter.default.removeObserver(self, name: NSWindow.didChangeScreenNotification,
object: self.window)
}
super.viewWillMove(toWindow: newWindow)
if (newWindow != nil) {
NotificationCenter.default.addObserver(self, selector: #selector(ClipView.updateCVDisplay(_:)), name: NSWindow.didChangeScreenNotification, object: newWindow)
if newWindow != nil {
NotificationCenter.default.addObserver(self, selector: #selector(ClipView.updateCVDisplay(_:)),
name: NSWindow.didChangeScreenNotification,
object: newWindow)
}
}

Expand All @@ -79,23 +78,22 @@ open class ClipView : NSClipView {
// return rect
// }

var _displayLink : CVDisplayLink?
var _displayLink: CVDisplayLink?

var displayLink : CVDisplayLink {
var displayLink: CVDisplayLink {
if let link = _displayLink { return link }

let linkCallback : CVDisplayLinkOutputCallback = {( displayLink, _, _, _, _, displayLinkContext) -> CVReturn in
let linkCallback: CVDisplayLinkOutputCallback = {( displayLink, _, _, _, _, displayLinkContext) -> CVReturn in
unsafeBitCast(displayLinkContext, to: ClipView.self).updateOrigin()
return kCVReturnSuccess
}
var link : CVDisplayLink?
var link: CVDisplayLink?
CVDisplayLinkCreateWithActiveCGDisplays(&link)
CVDisplayLinkSetOutputCallback(link!, linkCallback, UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque()))
self._displayLink = link
return link!
}


open override func mouseDown(with event: NSEvent) {
self.cancelScrollAnimation()
super.mouseDown(with: event)
Expand Down Expand Up @@ -140,10 +138,9 @@ open class ClipView : NSClipView {
return success
}


func finishedScrolling(_ success: Bool) {
self.completionBlock?(success)
self.completionBlock = nil;
self.completionBlock = nil
}

open override func scroll(to newOrigin: NSPoint) {
Expand Down Expand Up @@ -181,7 +178,7 @@ open class ClipView : NSClipView {
if self.window == nil {
cancel = true
}
o = self.bounds.origin;
o = self.bounds.origin
integral = self.window?.backingScaleFactor == 1
}

Expand All @@ -190,12 +187,12 @@ open class ClipView : NSClipView {
return
}

let lastOrigin = o;
let deceleration = self.decelerationRate;
let lastOrigin = o
let deceleration = self.decelerationRate

// Calculate the next origin on a basic ease-out curve.
o.x = o.x * deceleration + self.destinationOrigin.x * (1 - self.decelerationRate);
o.y = o.y * deceleration + self.destinationOrigin.y * (1 - self.decelerationRate);
o.x = o.x * deceleration + self.destinationOrigin.x * (1 - self.decelerationRate)
o.y = o.y * deceleration + self.destinationOrigin.y * (1 - self.decelerationRate)

if integral {
o = o.integral
Expand All @@ -213,7 +210,7 @@ open class ClipView : NSClipView {

//.postNotificationName(NSScrollViewDidLiveScrollNotification, object: self, userInfo: nil)

if ((fabs(o.x - lastOrigin.x) < 0.1 && fabs(o.y - lastOrigin.y) < 0.1)) {
if fabs(o.x - lastOrigin.x) < 0.1 && fabs(o.y - lastOrigin.y) < 0.1 {
self.endScrolling()

// Make sure we always finish out the animation with the actual coordinates
Expand Down Expand Up @@ -244,10 +241,4 @@ open class ClipView : NSClipView {
CVDisplayLinkStop(self.displayLink)
}







}
14 changes: 4 additions & 10 deletions CollectionView/CollapsableCollectionViewProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@

import Foundation


public class CollapsableCollectionViewProvider : CollectionViewResultsProxy {
public class CollapsableCollectionViewProvider: CollectionViewResultsProxy {

/// When set as the delegate
public unowned let collectionView : CollectionView
public unowned let resultsController : ResultsController
public unowned let collectionView: CollectionView
public unowned let resultsController: ResultsController
public weak var delegate: CollectionViewProviderDelegate?

/// The last known section count of real data
Expand Down Expand Up @@ -48,14 +47,11 @@ public class CollapsableCollectionViewProvider : CollectionViewResultsProxy {

*/
public var populateWhenEmpty = false



}

// MARK: - Results Controller Delegate
/*-------------------------------------------------------------------------------*/
extension CollapsableCollectionViewProvider : ResultsControllerDelegate {
extension CollapsableCollectionViewProvider: ResultsControllerDelegate {

public func controllerDidLoadContent(controller: ResultsController) {
self.sectionCount = controller.numberOfSections
Expand Down Expand Up @@ -99,5 +95,3 @@ extension CollapsableCollectionViewProvider : ResultsControllerDelegate {
self.collectionView.applyChanges(from: self, completion: completion)
}
}


Loading

0 comments on commit 3a32809

Please sign in to comment.