Skip to content

Commit 06e0975

Browse files
author
andela-gukpere
committed
feature(Swift 3.0 Deprecations): Fix deprecations for Swift 3
1 parent eb3dc6a commit 06e0975

File tree

9 files changed

+95
-94
lines changed

9 files changed

+95
-94
lines changed

IOSSwiftBoiler.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
/* End PBXContainerItemProxy section */
5454

5555
/* Begin PBXFileReference section */
56+
002A54961C9CC3B7007BB885 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Main.strings; sourceTree = "<group>"; };
5657
008681B01C9A355B0036D514 /* IOSSwiftBoiler.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = IOSSwiftBoiler.app; sourceTree = BUILT_PRODUCTS_DIR; };
5758
008681B31C9A355B0036D514 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
5859
008681B81C9A355B0036D514 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
@@ -79,7 +80,6 @@
7980
008682001C9A395B0036D514 /* Assets */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Assets; sourceTree = "<group>"; };
8081
008682021C9A39830036D514 /* FBSDKCoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = FBSDKCoreKit.framework; sourceTree = "<group>"; };
8182
008682031C9A39830036D514 /* FBSDKLoginKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = FBSDKLoginKit.framework; sourceTree = "<group>"; };
82-
008682061C9A3E300036D514 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Main.strings; sourceTree = "<group>"; };
8383
0086820F1C9A3E680036D514 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
8484
008682111C9A3E6B0036D514 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Localizable.strings; sourceTree = "<group>"; };
8585
008682131C9A3EA90036D514 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Main.strings; sourceTree = "<group>"; };
@@ -479,8 +479,8 @@
479479
isa = PBXVariantGroup;
480480
children = (
481481
008681B81C9A355B0036D514 /* Base */,
482-
008682061C9A3E300036D514 /* de */,
483482
008682131C9A3EA90036D514 /* en */,
483+
002A54961C9CC3B7007BB885 /* de */,
484484
);
485485
name = Main.storyboard;
486486
sourceTree = "<group>";

IOSSwiftBoiler/LoginViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class LoginViewController: UIViewController, UIGestureRecognizerDelegate {
3131
playBgVideo()
3232

3333
// Add Pull up / down Swipe to close to View
34-
panGestureRecognizer = UIPanGestureRecognizer(target: self, action: "panRecognized:")
34+
panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(panRecognized(_:)))
3535
panGestureRecognizer.delegate = self
3636
view.addGestureRecognizer(panGestureRecognizer)
3737
}
@@ -241,7 +241,7 @@ class LoginViewController: UIViewController, UIGestureRecognizerDelegate {
241241

242242
// Add observer to help repeat background video when it completes
243243
notificationCenter.addObserver(self,
244-
selector: "playerItemDidReachEnd:",
244+
selector: #selector(playerItemDidReachEnd(_:)),
245245
name: AVPlayerItemDidPlayToEndTimeNotification,
246246
object: player?.currentItem)
247247

IOSSwiftBoiler/MarqueeLabel.swift

Lines changed: 76 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ public class MarqueeLabel: UILabel {
3030
//
3131

3232
/**
33-
Defines the direction and method in which the `MarqueeLabel` instance scrolls.
34-
`MarqueeLabel` supports four types of scrolling: `MLLeftRight`, `MLRightLeft`, `MLContinuous`, and `MLContinuousReverse`.
35-
36-
Given the nature of how text direction works, the options for the `marqueeType` property require specific text alignments
37-
and will set the textAlignment property accordingly.
38-
39-
- `MLLeftRight` type is ONLY compatible with a label text alignment of `NSTextAlignmentLeft`.
40-
- `MLRightLeft` type is ONLY compatible with a label text alignment of `NSTextAlignmentRight`.
41-
- `MLContinuous` does not require a text alignment (it is effectively centered).
42-
- `MLContinuousReverse` does not require a text alignment (it is effectively centered).
43-
44-
Defaults to `MLContinuous`.
45-
46-
- SeeAlso: Type
47-
- SeeAlso: textAlignment
48-
*/
33+
Defines the direction and method in which the `MarqueeLabel` instance scrolls.
34+
`MarqueeLabel` supports four types of scrolling: `MLLeftRight`, `MLRightLeft`, `MLContinuous`, and `MLContinuousReverse`.
35+
36+
Given the nature of how text direction works, the options for the `marqueeType` property require specific text alignments
37+
and will set the textAlignment property accordingly.
38+
39+
- `MLLeftRight` type is ONLY compatible with a label text alignment of `NSTextAlignmentLeft`.
40+
- `MLRightLeft` type is ONLY compatible with a label text alignment of `NSTextAlignmentRight`.
41+
- `MLContinuous` does not require a text alignment (it is effectively centered).
42+
- `MLContinuousReverse` does not require a text alignment (it is effectively centered).
43+
44+
Defaults to `MLContinuous`.
45+
46+
- SeeAlso: Type
47+
- SeeAlso: textAlignment
48+
*/
4949
public var type: Type = .Continuous {
5050
didSet {
5151
if type == oldValue {
@@ -132,7 +132,7 @@ public class MarqueeLabel: UILabel {
132132
didSet {
133133
if tapToScroll != oldValue {
134134
if tapToScroll {
135-
let tapRecognizer = UITapGestureRecognizer(target: self, action: "labelWasTapped:")
135+
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(MarqueeLabel.labelWasTapped(_:)))
136136
self.addGestureRecognizer(tapRecognizer)
137137
userInteractionEnabled = true
138138
} else {
@@ -317,20 +317,20 @@ public class MarqueeLabel: UILabel {
317317
//
318318

319319
/**
320-
Convenience method to restart all `MarqueeLabel` instances that have the specified view controller in their next responder chain.
321-
322-
- Parameter controller: The view controller for which to restart all `MarqueeLabel` instances.
323-
324-
- Warning: View controllers that appear with animation (such as from underneath a modal-style controller) can cause some `MarqueeLabel` text
325-
position "jumping" when this method is used in `viewDidAppear` if scroll animations are already underway. Use this method inside `viewWillAppear:`
326-
instead to avoid this problem.
327-
328-
- Warning: This method may not function properly if passed the parent view controller when using view controller containment.
329-
330-
- SeeAlso: restartLabel
331-
- SeeAlso: controllerViewDidAppear:
332-
- SeeAlso: controllerViewWillAppear:
333-
*/
320+
Convenience method to restart all `MarqueeLabel` instances that have the specified view controller in their next responder chain.
321+
322+
- Parameter controller: The view controller for which to restart all `MarqueeLabel` instances.
323+
324+
- Warning: View controllers that appear with animation (such as from underneath a modal-style controller) can cause some `MarqueeLabel` text
325+
position "jumping" when this method is used in `viewDidAppear` if scroll animations are already underway. Use this method inside `viewWillAppear:`
326+
instead to avoid this problem.
327+
328+
- Warning: This method may not function properly if passed the parent view controller when using view controller containment.
329+
330+
- SeeAlso: restartLabel
331+
- SeeAlso: controllerViewDidAppear:
332+
- SeeAlso: controllerViewWillAppear:
333+
*/
334334
class func restartLabelsOfController(controller: UIViewController) {
335335
MarqueeLabel.notifyController(controller, message: .Restart)
336336
}
@@ -391,14 +391,14 @@ public class MarqueeLabel: UILabel {
391391
//
392392

393393
/**
394-
Returns a newly initialized `MarqueeLabel` instance with the specified scroll rate and edge transparency fade length.
395-
396-
- Parameter frame: A rectangle specifying the initial location and size of the view in its superview's coordinates. Text (for the given font, font size, etc.) that does not fit in this frame will automatically scroll.
397-
- Parameter pixelsPerSec: A rate of scroll for the label scroll animation. Must be non-zero. Note that this will be the peak (mid-transition) rate for ease-type animation.
398-
- Parameter fadeLength: A length of transparency fade at the left and right edges of the `MarqueeLabel` instance's frame.
399-
- Returns: An initialized `MarqueeLabel` object or nil if the object couldn't be created.
400-
- SeeAlso: fadeLength
401-
*/
394+
Returns a newly initialized `MarqueeLabel` instance with the specified scroll rate and edge transparency fade length.
395+
396+
- Parameter frame: A rectangle specifying the initial location and size of the view in its superview's coordinates. Text (for the given font, font size, etc.) that does not fit in this frame will automatically scroll.
397+
- Parameter pixelsPerSec: A rate of scroll for the label scroll animation. Must be non-zero. Note that this will be the peak (mid-transition) rate for ease-type animation.
398+
- Parameter fadeLength: A length of transparency fade at the left and right edges of the `MarqueeLabel` instance's frame.
399+
- Returns: An initialized `MarqueeLabel` object or nil if the object couldn't be created.
400+
- SeeAlso: fadeLength
401+
*/
402402
init(frame: CGRect, rate: CGFloat, fadeLength fade: CGFloat) {
403403
speed = .Rate(rate)
404404
fadeLength = CGFloat(min(fade, frame.size.width/2.0))
@@ -455,12 +455,12 @@ public class MarqueeLabel: UILabel {
455455

456456
// Add notification observers
457457
// Custom class notifications
458-
NSNotificationCenter.defaultCenter().addObserver(self, selector: "restartForViewController:", name: MarqueeKeys.Restart.rawValue, object: nil)
459-
NSNotificationCenter.defaultCenter().addObserver(self, selector: "labelizeForController:", name: MarqueeKeys.Labelize.rawValue, object: nil)
460-
NSNotificationCenter.defaultCenter().addObserver(self, selector: "animateForController:", name: MarqueeKeys.Animate.rawValue, object: nil)
458+
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(restartForViewController(_:)), name: MarqueeKeys.Restart.rawValue, object: nil)
459+
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(labelizeForController(_:)), name: MarqueeKeys.Labelize.rawValue, object: nil)
460+
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(animateForController(_:)), name: MarqueeKeys.Animate.rawValue, object: nil)
461461
// UIApplication state notifications
462-
NSNotificationCenter.defaultCenter().addObserver(self, selector: "restartLabel", name: UIApplicationDidBecomeActiveNotification, object: nil)
463-
NSNotificationCenter.defaultCenter().addObserver(self, selector: "shutdownLabel", name: UIApplicationDidEnterBackgroundNotification, object: nil)
462+
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(restartLabel), name: UIApplicationDidBecomeActiveNotification, object: nil)
463+
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(shutdownLabel), name: UIApplicationDidEnterBackgroundNotification, object: nil)
464464
}
465465

466466
override public func awakeFromNib() {
@@ -470,17 +470,17 @@ public class MarqueeLabel: UILabel {
470470

471471
private func forwardPropertiesToSublabel() {
472472
/*
473-
Note that this method is currently ONLY called from awakeFromNib, i.e. when
474-
text properties are set via a Storyboard. As the Storyboard/IB doesn't currently
475-
support attributed strings, there's no need to "forward" the super attributedString value.
476-
*/
473+
Note that this method is currently ONLY called from awakeFromNib, i.e. when
474+
text properties are set via a Storyboard. As the Storyboard/IB doesn't currently
475+
support attributed strings, there's no need to "forward" the super attributedString value.
476+
*/
477477

478478
// Since we're a UILabel, we actually do implement all of UILabel's properties.
479479
// We don't care about these values, we just want to forward them on to our sublabel.
480480
let properties = ["baselineAdjustment", "enabled", "highlighted", "highlightedTextColor",
481-
"minimumFontSize", "shadowOffset", "textAlignment",
482-
"userInteractionEnabled", "adjustsFontSizeToFitWidth",
483-
"lineBreakMode", "numberOfLines"]
481+
"minimumFontSize", "shadowOffset", "textAlignment",
482+
"userInteractionEnabled", "adjustsFontSizeToFitWidth",
483+
"lineBreakMode", "numberOfLines"]
484484

485485
// Iterate through properties
486486
sublabel.text = super.text
@@ -725,7 +725,8 @@ public class MarqueeLabel: UILabel {
725725
// Define animation completion closure type
726726
private typealias MLAnimationCompletion = (finished: Bool) -> ()
727727

728-
private func scroll(interval: CGFloat, delay: CGFloat = 0.0, var scroller: Scroller, fader: CAKeyframeAnimation?) {
728+
private func scroll(interval: CGFloat, delay: CGFloat = 0.0, scroller_: Scroller, fader: CAKeyframeAnimation?) {
729+
var scroller:Scroller = scroller_
729730
// Check for conditions which would prevent scrolling
730731
if !labelReadyForScroll() {
731732
return
@@ -780,7 +781,7 @@ public class MarqueeLabel: UILabel {
780781
// Begin again, if conditions met
781782
if (self.labelShouldScroll() && !self.tapToScroll && !self.holdScrolling) {
782783
// Perform completion callback
783-
self.scroll(interval, delay: delay, scroller: scroller, fader: gradientAnimation)
784+
self.scroll(interval, delay: delay, scroller_: scroller, fader: gradientAnimation)
784785
}
785786
}
786787
})
@@ -827,7 +828,7 @@ public class MarqueeLabel: UILabel {
827828
})
828829

829830
// Scroll
830-
scroll(interval, delay: delay, scroller: scroller, fader: nil)
831+
scroll(interval, delay: delay, scroller_: scroller, fader: nil)
831832
}
832833

833834

@@ -852,7 +853,7 @@ public class MarqueeLabel: UILabel {
852853
})
853854

854855
// Scroll
855-
scroll(interval, delay: delay, scroller: scroller, fader: nil)
856+
scroll(interval, delay: delay, scroller_: scroller, fader: nil)
856857
}
857858

858859
private func applyGradientMask(fadeLength: CGFloat, animated: Bool) {
@@ -905,7 +906,7 @@ public class MarqueeLabel: UILabel {
905906
case .ContinuousReverse, .RightLeft:
906907
adjustedColors = [(trailingFadeNeeded ? transparent : opaque), opaque, opaque, opaque]
907908

908-
// .MLContinuous, .MLLeftRight
909+
// .MLContinuous, .MLLeftRight
909910
default:
910911
adjustedColors = [opaque, opaque, opaque, (trailingFadeNeeded ? transparent : opaque)]
911912
break
@@ -964,7 +965,7 @@ public class MarqueeLabel: UILabel {
964965
1.0 // 9) End of LE fade out, just as scroll home finishes
965966
]
966967

967-
// .MLContinuous, .MLContinuousReverse
968+
// .MLContinuous, .MLContinuousReverse
968969
default:
969970
// Calculate total animation duration
970971
let totalDuration = delay + interval
@@ -1081,7 +1082,7 @@ public class MarqueeLabel: UILabel {
10811082
]
10821083

10831084
// .Continuous
1084-
// .ContinuousReverse
1085+
// .ContinuousReverse
10851086
default:
10861087
//NSAssert(values.count == 3, @"Incorrect number of values passed for MLContinous-type animation")
10871088
totalDuration = delay + interval
@@ -1212,19 +1213,19 @@ public class MarqueeLabel: UILabel {
12121213
//
12131214

12141215
/**
1215-
Overrides any non-size condition which is preventing the receiver from automatically scrolling, and begins a scroll animation.
1216-
1217-
Currently the only non-size conditions which can prevent a label from scrolling are the `tapToScroll` and `holdScrolling` properties. This
1218-
method will not force a label with a string that fits inside the label bounds (i.e. that would not automatically scroll) to begin a scroll
1219-
animation.
1220-
1221-
Upon the completion of the first forced scroll animation, the receiver will not automatically continue to scroll unless the conditions
1222-
preventing scrolling have been removed.
1223-
1224-
- Note: This method has no effect if called during an already in-flight scroll animation.
1225-
1226-
- SeeAlso: restartLabel
1227-
*/
1216+
Overrides any non-size condition which is preventing the receiver from automatically scrolling, and begins a scroll animation.
1217+
1218+
Currently the only non-size conditions which can prevent a label from scrolling are the `tapToScroll` and `holdScrolling` properties. This
1219+
method will not force a label with a string that fits inside the label bounds (i.e. that would not automatically scroll) to begin a scroll
1220+
animation.
1221+
1222+
Upon the completion of the first forced scroll animation, the receiver will not automatically continue to scroll unless the conditions
1223+
preventing scrolling have been removed.
1224+
1225+
- Note: This method has no effect if called during an already in-flight scroll animation.
1226+
1227+
- SeeAlso: restartLabel
1228+
*/
12281229
public func triggerScrollStart() {
12291230
if labelShouldScroll() && !awayFromHome {
12301231
beginScroll()
@@ -1368,8 +1369,8 @@ public class MarqueeLabel: UILabel {
13681369

13691370
#if os(iOS)
13701371
override public func viewForBaselineLayout() -> UIView {
1371-
// Use subLabel view for handling baseline layouts
1372-
return sublabel
1372+
// Use subLabel view for handling baseline layouts
1373+
return sublabel
13731374
}
13741375
#endif
13751376

@@ -1651,7 +1652,7 @@ private extension CAMediaTimingFunction {
16511652
var t1 = y_0
16521653
var f0, df0: CGFloat
16531654

1654-
for (var i = 0; i < 15; i++) {
1655+
for _ in 0 ..< 15 {
16551656
// Base this iteration of t1 calculated from last iteration
16561657
t0 = t1
16571658
// Calculate f(t0)
@@ -1724,7 +1725,7 @@ private extension CAMediaTimingFunction {
17241725
// Create point array to point to
17251726
var point: [Float] = [0.0, 0.0]
17261727
var pointArray = [CGPoint]()
1727-
for (var i: Int = 0; i <= 3; i++) {
1728+
for i in 0 ..< 4 {
17281729
self.getControlPointAtIndex(i, values: &point)
17291730
pointArray.append(CGPoint(x: CGFloat(point[0]), y: CGFloat(point[1])))
17301731
}

IOSSwiftBoiler/TextHeadingView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class TextHeadingView: UIView {
5151
view.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
5252
addSubview(view)
5353
textLabel = textLabel ?? view.subviews[0] as! UILabel
54-
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "tapAction:"))
54+
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tapAction(_:))))
5555
}
5656
}
5757
}

IOSSwiftBoiler/UserViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class UserViewController: UIViewController {
2424

2525
override func viewDidLoad() {
2626
super.viewDidLoad()
27-
notificationCenter.addObserver(self, selector: "loginStatusUpdated:", name: Const.NOTIFICATION_USER_AUTH, object: nil)
27+
notificationCenter.addObserver(self, selector: #selector(loginStatusUpdated(_:)), name: Const.NOTIFICATION_USER_AUTH, object: nil)
2828

2929
populate()
3030
}

IOSSwiftBoiler/Users.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class Users: NSManagedObject {
100100
}
101101

102102
context.deleteObject(managedObject)
103-
count++
103+
count += 1
104104
}
105105

106106
Helpers.saveManagedContext(context: context) {

IOSSwiftBoiler/WebViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class WebViewController: UIViewController, UIWebViewDelegate {
3636
func webViewDidStartLoad(webView: UIWebView) {
3737
progressView.progress = 0.0
3838
progressView.hidden = false
39-
timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: "timerCallback", userInfo: nil, repeats: true)
39+
timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: #selector(timerCallback), userInfo: nil, repeats: true)
4040
}
4141

4242
func webViewDidFinishLoad(webView: UIWebView) {

0 commit comments

Comments
 (0)