Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update swift version (up to 5.0) #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Example/PullToRefreshSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -394,7 +395,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "dekatotoro.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -407,7 +408,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "dekatotoro.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion Example/PullToRefreshSwift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
internal func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}

Expand Down
2 changes: 1 addition & 1 deletion Example/PullToRefreshSwift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "Cell")
let cell: UITableViewCell = UITableViewCell(style: UITableViewCell.CellStyle.subtitle, reuseIdentifier: "Cell")
cell.textLabel?.font = UIFont.italicSystemFont(ofSize: 18)
cell.textLabel?.textColor = UIColor(red: 44/255, green: 62/255, blue: 88/255, alpha: 1.0)
cell.textLabel?.text = texts[(indexPath as NSIndexPath).row]
Expand Down
14 changes: 7 additions & 7 deletions Source/PullToRefreshView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//
import UIKit

private var kvoContext = "PullToRefreshKVOContext"

open class PullToRefreshView: UIView {
enum PullToRefreshState {
case pulling
Expand All @@ -19,14 +21,12 @@ open class PullToRefreshView: UIView {
// MARK: Variables
let contentOffsetKeyPath = "contentOffset"
let contentSizeKeyPath = "contentSize"
var kvoContext = "PullToRefreshKVOContext"

fileprivate var options: PullToRefreshOption
fileprivate var backgroundView: UIView
fileprivate var arrow: UIImageView
fileprivate var indicator: UIActivityIndicatorView
fileprivate var scrollViewInsets: UIEdgeInsets = UIEdgeInsets.zero
fileprivate var refreshCompletion: ((Void) -> Void)?
fileprivate var refreshCompletion: (() -> Void)?
fileprivate var pull: Bool = true

fileprivate var positionY:CGFloat = 0 {
Expand Down Expand Up @@ -78,21 +78,21 @@ open class PullToRefreshView: UIView {
fatalError("init(coder:) has not been implemented")
}

public init(options: PullToRefreshOption, frame: CGRect, refreshCompletion :((Void) -> Void)?, down:Bool=true) {
public init(options: PullToRefreshOption, frame: CGRect, refreshCompletion :(() -> Void)?, down:Bool=true) {
self.options = options
self.refreshCompletion = refreshCompletion

self.backgroundView = UIView(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height))
self.backgroundView.backgroundColor = self.options.backgroundColor
self.backgroundView.autoresizingMask = UIViewAutoresizing.flexibleWidth
self.backgroundView.autoresizingMask = UIView.AutoresizingMask.flexibleWidth

self.arrow = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
self.arrow.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin]

self.arrow.image = UIImage(named: PullToRefreshConst.imageName, in: Bundle(for: type(of: self)), compatibleWith: nil)


self.indicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
self.indicator = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.gray)
self.indicator.bounds = self.arrow.bounds
self.indicator.autoresizingMask = self.arrow.autoresizingMask
self.indicator.hidesWhenStopped = true
Expand Down Expand Up @@ -262,7 +262,7 @@ open class PullToRefreshView: UIView {
fileprivate func arrowRotation() {
UIView.animate(withDuration: 0.2, delay: 0, options:[], animations: {
// -0.0000001 for the rotation direction control
self.arrow.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI-0.0000001))
self.arrow.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi - 0.0000001))
}, completion:nil)
}

Expand Down
18 changes: 9 additions & 9 deletions Source/UIScrollViewExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ public extension UIScrollView {
return pullToRefreshView as? PullToRefreshView
}

public func addPullRefresh(options: PullToRefreshOption = PullToRefreshOption(), refreshCompletion :((Void) -> Void)?) {
func addPullRefresh(options: PullToRefreshOption = PullToRefreshOption(), refreshCompletion :(() -> Void)?) {
let refreshViewFrame = CGRect(x: 0, y: -PullToRefreshConst.height, width: self.frame.size.width, height: PullToRefreshConst.height)
let refreshView = PullToRefreshView(options: options, frame: refreshViewFrame, refreshCompletion: refreshCompletion)
refreshView.tag = PullToRefreshConst.pullTag
addSubview(refreshView)
}

public func addPushRefresh(options: PullToRefreshOption = PullToRefreshOption(), refreshCompletion :((Void) -> Void)?) {
func addPushRefresh(options: PullToRefreshOption = PullToRefreshOption(), refreshCompletion :(() -> Void)?) {
let refreshViewFrame = CGRect(x: 0, y: contentSize.height, width: self.frame.size.width, height: PullToRefreshConst.height)
let refreshView = PullToRefreshView(options: options, frame: refreshViewFrame, refreshCompletion: refreshCompletion,down: false)
refreshView.tag = PullToRefreshConst.pushTag
addSubview(refreshView)
}

public func startPullRefresh() {
func startPullRefresh() {
let refreshView = self.refreshViewWithTag(PullToRefreshConst.pullTag)
refreshView?.state = .refreshing
}

public func stopPullRefreshEver(_ ever:Bool = false) {
func stopPullRefreshEver(_ ever:Bool = false) {
let refreshView = self.refreshViewWithTag(PullToRefreshConst.pullTag)
if ever {
refreshView?.state = .finish
Expand All @@ -42,17 +42,17 @@ public extension UIScrollView {
}
}

public func removePullRefresh() {
func removePullRefresh() {
let refreshView = self.refreshViewWithTag(PullToRefreshConst.pullTag)
refreshView?.removeFromSuperview()
}

public func startPushRefresh() {
func startPushRefresh() {
let refreshView = self.refreshViewWithTag(PullToRefreshConst.pushTag)
refreshView?.state = .refreshing
}

public func stopPushRefreshEver(_ ever:Bool = false) {
func stopPushRefreshEver(_ ever:Bool = false) {
let refreshView = self.refreshViewWithTag(PullToRefreshConst.pushTag)
if ever {
refreshView?.state = .finish
Expand All @@ -61,13 +61,13 @@ public extension UIScrollView {
}
}

public func removePushRefresh() {
func removePushRefresh() {
let refreshView = self.refreshViewWithTag(PullToRefreshConst.pushTag)
refreshView?.removeFromSuperview()
}

// If you want to PullToRefreshView fixed top potision, Please call this function in scrollViewDidScroll
public func fixedPullToRefreshViewForDidScroll() {
func fixedPullToRefreshViewForDidScroll() {
let pullToRefreshView = self.refreshViewWithTag(PullToRefreshConst.pullTag)
if !PullToRefreshConst.fixedTop || pullToRefreshView == nil {
return
Expand Down