Skip to content

Commit

Permalink
Migrate swift language version from 4.0 to 4.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
WenchaoD committed Sep 24, 2018
1 parent f280708 commit 985890d
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wenchaod.FSPagerViewExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -473,7 +473,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wenchaod.FSPagerViewExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
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 {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
8 changes: 6 additions & 2 deletions FSPagerView/FSPagerView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
F9580B751E5D9F0600C5B267 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = HZF422TY46;
LastSwiftMigration = 1000;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -299,6 +300,7 @@
F9580B7F1E5D9F0600C5B267 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = HZF422TY46;
Expand All @@ -312,13 +314,15 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wenchaod.FSPagerView;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
};
name = Debug;
};
F9580B801E5D9F0600C5B267 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = HZF422TY46;
Expand All @@ -332,7 +336,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wenchaod.FSPagerView;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.wenchaod.FSPagerView-Objc";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -544,7 +544,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.wenchaod.FSPagerView-Objc";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
30 changes: 15 additions & 15 deletions Sources/FSPageControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ open class FSPageControl: UIControl {
}

/// The horizontal alignment of content within the control’s bounds. Default is center.
open override var contentHorizontalAlignment: UIControlContentHorizontalAlignment {
open override var contentHorizontalAlignment: UIControl.ContentHorizontalAlignment {
didSet {
self.setNeedsLayout()
}
Expand All @@ -66,12 +66,12 @@ open class FSPageControl: UIControl {
}
}

internal var strokeColors: [UIControlState: UIColor] = [:]
internal var fillColors: [UIControlState: UIColor] = [:]
internal var paths: [UIControlState: UIBezierPath] = [:]
internal var images: [UIControlState: UIImage] = [:]
internal var alphas: [UIControlState: CGFloat] = [:]
internal var transforms: [UIControlState: CGAffineTransform] = [:]
internal var strokeColors: [UIControl.State: UIColor] = [:]
internal var fillColors: [UIControl.State: UIColor] = [:]
internal var paths: [UIControl.State: UIBezierPath] = [:]
internal var images: [UIControl.State: UIImage] = [:]
internal var alphas: [UIControl.State: CGFloat] = [:]
internal var transforms: [UIControl.State: CGAffineTransform] = [:]

fileprivate weak var contentView: UIView!

Expand Down Expand Up @@ -120,7 +120,7 @@ open class FSPageControl: UIControl {
}
}()
for (index,value) in self.indicatorLayers.enumerated() {
let state: UIControlState = (index == self.currentPage) ? .selected : .normal
let state: UIControl.State = (index == self.currentPage) ? .selected : .normal
let image = self.images[state]
let size = image?.size ?? CGSize(width: diameter, height: diameter)
let origin = CGPoint(x: x - (size.width-diameter)*0.5, y: self.contentView.bounds.midY-size.height*0.5)
Expand All @@ -136,7 +136,7 @@ open class FSPageControl: UIControl {
/// - strokeColor: The stroke color to use for the specified state.
/// - state: The state that uses the specified stroke color.
@objc(setStrokeColor:forState:)
open func setStrokeColor(_ strokeColor: UIColor?, for state: UIControlState) {
open func setStrokeColor(_ strokeColor: UIColor?, for state: UIControl.State) {
guard self.strokeColors[state] != strokeColor else {
return
}
Expand All @@ -150,7 +150,7 @@ open class FSPageControl: UIControl {
/// - fillColor: The fill color to use for the specified state.
/// - state: The state that uses the specified fill color.
@objc(setFillColor:forState:)
open func setFillColor(_ fillColor: UIColor?, for state: UIControlState) {
open func setFillColor(_ fillColor: UIColor?, for state: UIControl.State) {
guard self.fillColors[state] != fillColor else {
return
}
Expand All @@ -164,7 +164,7 @@ open class FSPageControl: UIControl {
/// - image: The image to use for the specified state.
/// - state: The state that uses the specified image.
@objc(setImage:forState:)
open func setImage(_ image: UIImage?, for state: UIControlState) {
open func setImage(_ image: UIImage?, for state: UIControl.State) {
guard self.images[state] != image else {
return
}
Expand All @@ -179,7 +179,7 @@ open class FSPageControl: UIControl {
/// - Parameters:
/// - alpha: The alpha value to use for the specified state.
/// - state: The state that uses the specified alpha.
open func setAlpha(_ alpha: CGFloat, for state: UIControlState) {
open func setAlpha(_ alpha: CGFloat, for state: UIControl.State) {
guard self.alphas[state] != alpha else {
return
}
Expand All @@ -193,7 +193,7 @@ open class FSPageControl: UIControl {
/// - path: The path to use for the specified state.
/// - state: The state that uses the specified path.
@objc(setPath:forState:)
open func setPath(_ path: UIBezierPath?, for state: UIControlState) {
open func setPath(_ path: UIBezierPath?, for state: UIControl.State) {
guard self.paths[state] != path else {
return
}
Expand Down Expand Up @@ -241,7 +241,7 @@ open class FSPageControl: UIControl {

fileprivate func updateIndicatorAttributes(for layer: CAShapeLayer) {
let index = self.indicatorLayers.index(of: layer)
let state: UIControlState = index == self.currentPage ? .selected : .normal
let state: UIControl.State = index == self.currentPage ? .selected : .normal
if let image = self.images[state] {
layer.strokeColor = nil
layer.fillColor = nil
Expand Down Expand Up @@ -300,7 +300,7 @@ open class FSPageControl: UIControl {

}

extension UIControlState: Hashable {
extension UIControl.State: Hashable {
public var hashValue: Int {
return Int((6777*self.rawValue+3777)%UInt(UInt16.max))
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/FSPageViewLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FSPagerViewLayout: UICollectionViewLayout {
internal var leadingSpacing: CGFloat = 0
internal var itemSpacing: CGFloat = 0
internal var needsReprepare = true
internal var scrollDirection: FSPagerViewScrollDirection = .horizontal
internal var scrollDirection: FSPagerView.ScrollDirection = .horizontal

open override class var layoutAttributesClass: AnyClass {
get {
Expand Down Expand Up @@ -45,7 +45,7 @@ class FSPagerViewLayout: UICollectionViewLayout {

deinit {
#if !os(tvOS)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil)
#endif
}

Expand Down Expand Up @@ -129,7 +129,7 @@ class FSPagerViewLayout: UICollectionViewLayout {
var origin = startPosition
let maxPosition = self.scrollDirection == .horizontal ? min(rect.maxX,self.contentSize.width-self.actualItemSize.width-self.leadingSpacing) : min(rect.maxY,self.contentSize.height-self.actualItemSize.height-self.leadingSpacing)
// https://stackoverflow.com/a/10335601/2398107
while origin-maxPosition <= max(CGFloat(100.0) * .ulpOfOne * fabs(origin+maxPosition), .leastNonzeroMagnitude) {
while origin-maxPosition <= max(CGFloat(100.0) * .ulpOfOne * abs(origin+maxPosition), .leastNonzeroMagnitude) {
let indexPath = IndexPath(item: itemIndex%self.numberOfItems, section: itemIndex/self.numberOfItems)
let attributes = self.layoutAttributesForItem(at: indexPath) as! FSPagerViewLayoutAttributes
self.applyTransform(to: attributes, with: self.pagerView?.transformer)
Expand Down Expand Up @@ -260,7 +260,7 @@ class FSPagerViewLayout: UICollectionViewLayout {

fileprivate func commonInit() {
#if !os(tvOS)
NotificationCenter.default.addObserver(self, selector: #selector(didReceiveNotification(notification:)), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didReceiveNotification(notification:)), name: UIDevice.orientationDidChangeNotification, object: nil)
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/FSPagerCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FSPagerViewCollectionView: UICollectionView {

fileprivate func commonInit() {
self.contentInset = .zero
self.decelerationRate = UIScrollViewDecelerationRateFast
self.decelerationRate = UIScrollView.DecelerationRate.fast
self.showsVerticalScrollIndicator = false
self.showsHorizontalScrollIndicator = false
if #available(iOS 10.0, *) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/FSPagerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
@objc(selectItemAtIndex:animated:)
open func selectItem(at index: Int, animated: Bool) {
let indexPath = self.nearbyIndexPath(for: index)
let scrollPosition: UICollectionViewScrollPosition = self.scrollDirection == .horizontal ? .centeredHorizontally : .centeredVertically
let scrollPosition: UICollectionView.ScrollPosition = self.scrollDirection == .horizontal ? .centeredHorizontally : .centeredVertically
self.collectionView.selectItem(at: indexPath, animated: animated, scrollPosition: scrollPosition)
}

Expand Down Expand Up @@ -575,7 +575,7 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
return
}
self.timer = Timer.scheduledTimer(timeInterval: TimeInterval(self.automaticSlidingInterval), target: self, selector: #selector(self.flipNext(sender:)), userInfo: nil, repeats: true)
RunLoop.current.add(self.timer!, forMode: .commonModes)
RunLoop.current.add(self.timer!, forMode: .common)
}

@objc
Expand Down

0 comments on commit 985890d

Please sign in to comment.