Skip to content

Commit

Permalink
Add SwiftLint run script and fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
Piergiuseppe Longo committed Dec 20, 2016
1 parent e075f48 commit 3098b1c
Show file tree
Hide file tree
Showing 19 changed files with 174 additions and 156 deletions.
4 changes: 4 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
excluded: # paths to ignore during linting. overridden byincluded.
- Pods
line_length: 200
cyclomatic_complexity: 15
30 changes: 15 additions & 15 deletions Demo/DemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,47 @@ import UIKit
import PKHUD

class DemoViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

HUD.dimsBackground = false
HUD.allowsInteraction = false
}

@IBAction func showAnimatedSuccessHUD(_ sender: AnyObject) {
HUD.flash(.success, delay: 2.0)
}

@IBAction func showAnimatedErrorHUD(_ sender: AnyObject) {
HUD.show(.error)
HUD.hide(afterDelay: 2.0)
}

@IBAction func showAnimatedProgressHUD(_ sender: AnyObject) {
HUD.show(.progress)

// Now some long running task starts...
delay(2.0) {
// ...and once it finishes we flash the HUD for a second.
HUD.flash(.success, delay: 1.0)
}
}

@IBAction func showCustomProgressHUD(_ sender: AnyObject) {
HUD.flash(.rotatingImage(UIImage(named: "progress")), delay: 2.0)
}

@IBAction func showAnimatedStatusProgressHUD(_ sender: AnyObject) {
HUD.flash(.labeledProgress(title: "Title", subtitle: "Subtitle"), delay: 2.0)
}

@IBAction func showTextHUD(_ sender: AnyObject) {
HUD.flash(.label("Requesting Licence…"), delay: 2.0) { _ in
print("License Obtained.")
}
}

/*

Please note that the above demonstrates the "porcelain" interface - a more concise and clean way to work with the HUD.
Expand All @@ -60,16 +60,16 @@ class DemoViewController: UIViewController {
PKHUD.sharedHUD.contentView = PKHUDSuccessView(title: "Success!", subtitle: nil)
PKHUD.sharedHUD.hide(afterDelay: 2.0)
*/
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.allButUpsideDown
}
override var preferredStatusBarStyle : UIStatusBarStyle {

override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
func delay(_ delay:Double, closure:@escaping ()->()) {

func delay(_ delay: Double, closure:@escaping ()->()) {
DispatchQueue.main.asyncAfter(
deadline: DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: closure)
}
Expand Down
24 changes: 21 additions & 3 deletions PKHUD.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
F99631F919514FAC001F73CA /* Frameworks */,
F99631FA19514FAC001F73CA /* Resources */,
F996323A19514FD8001F73CA /* Embed Frameworks */,
120437181E09E1A400D7C7A5 /* SwiftLint */,
);
buildRules = (
);
Expand Down Expand Up @@ -276,8 +277,8 @@
TargetAttributes = {
F99631FB19514FAC001F73CA = {
CreatedOnToolsVersion = 6.0;
DevelopmentTeam = 5EHDAGHZ78;
LastSwiftMigration = 0800;
ProvisioningStyle = Manual;
};
F996321D19514FD8001F73CA = {
CreatedOnToolsVersion = 6.0;
Expand Down Expand Up @@ -324,6 +325,23 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
120437181E09E1A400D7C7A5 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = SwiftLint;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
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\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
F99631F819514FAC001F73CA /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down Expand Up @@ -466,7 +484,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 5EHDAGHZ78;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Demo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -480,7 +498,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 5EHDAGHZ78;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Demo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
18 changes: 9 additions & 9 deletions PKHUD/FrameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit

/// Provides the general look and feel of the PKHUD, into which the eventual content is inserted.
internal class FrameView: UIVisualEffectView {

internal init() {
super.init(effect: UIBlurEffect(style: .light))
commonInit()
Expand All @@ -21,30 +21,30 @@ internal class FrameView: UIVisualEffectView {
super.init(coder: aDecoder)
commonInit()
}

fileprivate func commonInit() {
backgroundColor = UIColor(white: 0.8, alpha: 0.36)
layer.cornerRadius = 9.0
layer.masksToBounds = true

contentView.addSubview(self.content)

let offset = 20.0

let motionEffectsX = UIInterpolatingMotionEffect(keyPath: "center.x", type: .tiltAlongHorizontalAxis)
motionEffectsX.maximumRelativeValue = offset
motionEffectsX.minimumRelativeValue = -offset

let motionEffectsY = UIInterpolatingMotionEffect(keyPath: "center.y", type: .tiltAlongVerticalAxis)
motionEffectsY.maximumRelativeValue = offset
motionEffectsY.minimumRelativeValue = -offset

let group = UIMotionEffectGroup()
group.motionEffects = [motionEffectsX, motionEffectsY]

addMotionEffect(group)
}

fileprivate var _content = UIView()
internal var content: UIView {
get {
Expand Down
29 changes: 14 additions & 15 deletions PKHUD/HUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,61 @@ public enum HUDContentType {
case progress
case image(UIImage?)
case rotatingImage(UIImage?)

case labeledSuccess(title: String?, subtitle: String?)
case labeledError(title: String?, subtitle: String?)
case labeledProgress(title: String?, subtitle: String?)
case labeledImage(image: UIImage?, title: String?, subtitle: String?)
case labeledRotatingImage(image: UIImage?, title: String?, subtitle: String?)

case label(String?)
case systemActivity
}

public final class HUD {

// MARK: Properties
public static var dimsBackground: Bool {
get { return PKHUD.sharedHUD.dimsBackground }
set { PKHUD.sharedHUD.dimsBackground = newValue }
}

public static var allowsInteraction: Bool {
get { return PKHUD.sharedHUD.userInteractionOnUnderlyingViewsEnabled }
set { PKHUD.sharedHUD.userInteractionOnUnderlyingViewsEnabled = newValue }
}

public static var isVisible: Bool { return PKHUD.sharedHUD.isVisible }

// MARK: Public methods, PKHUD based
public static func show(_ content: HUDContentType, onView view: UIView? = nil) {
PKHUD.sharedHUD.contentView = contentView(content)
PKHUD.sharedHUD.show(onView: view)
}

public static func hide(_ completion: ((Bool) -> Void)? = nil) {
PKHUD.sharedHUD.hide(animated: false, completion: completion)
}

public static func hide(animated: Bool, completion: ((Bool) -> Void)? = nil) {
PKHUD.sharedHUD.hide(animated: animated, completion: completion)
}

public static func hide(afterDelay delay: TimeInterval, completion: ((Bool) -> Void)? = nil) {
PKHUD.sharedHUD.hide(afterDelay: delay, completion: completion)
}

// MARK: Public methods, HUD based
public static func flash(_ content: HUDContentType, onView view: UIView? = nil) {
HUD.show(content, onView: view)
HUD.hide(animated: true, completion: nil)
}

public static func flash(_ content: HUDContentType, onView view: UIView? = nil, delay: TimeInterval, completion: ((Bool) -> Void)? = nil) {
HUD.show(content, onView: view)
HUD.hide(afterDelay: delay, completion: completion)
}

// MARK: Private methods
fileprivate static func contentView(_ content: HUDContentType) -> UIView {
switch content {
Expand All @@ -83,7 +83,7 @@ public final class HUD {
return PKHUDSquareBaseView(image: image)
case let .rotatingImage(image):
return PKHUDRotatingImageView(image: image)

case let .labeledSuccess(title, subtitle):
return PKHUDSuccessView(title: title, subtitle: subtitle)
case let .labeledError(title, subtitle):
Expand All @@ -94,8 +94,7 @@ public final class HUD {
return PKHUDSquareBaseView(image: image, title: title, subtitle: subtitle)
case let .labeledRotatingImage(image, title, subtitle):
return PKHUDRotatingImageView(image: image, title: title, subtitle: subtitle)



case let .label(text):
return PKHUDTextView(text: text)
case .systemActivity:
Expand Down
Loading

0 comments on commit 3098b1c

Please sign in to comment.