Skip to content

Commit 8a0d262

Browse files
committed
WIP: Swift3
1 parent a46795d commit 8a0d262

File tree

7 files changed

+60
-50
lines changed

7 files changed

+60
-50
lines changed

Example/NextGrowingTextView.xcodeproj/project.pbxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@
215215
TargetAttributes = {
216216
607FACCF1AFB9204008FA782 = {
217217
CreatedOnToolsVersion = 6.3.1;
218+
LastSwiftMigration = 0800;
218219
};
219220
607FACE41AFB9204008FA782 = {
220221
CreatedOnToolsVersion = 6.3.1;
@@ -495,6 +496,7 @@
495496
MODULE_NAME = ExampleApp;
496497
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
497498
PRODUCT_NAME = "$(TARGET_NAME)";
499+
SWIFT_VERSION = 3.0;
498500
};
499501
name = Debug;
500502
};
@@ -508,6 +510,7 @@
508510
MODULE_NAME = ExampleApp;
509511
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
510512
PRODUCT_NAME = "$(TARGET_NAME)";
513+
SWIFT_VERSION = 3.0;
511514
};
512515
name = Release;
513516
};

Example/NextGrowingTextView/AppDelegate.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
var window: UIWindow?
1515

1616

17-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
17+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1818
// Override point for customization after application launch.
1919
return true
2020
}
2121

22-
func applicationWillResignActive(application: UIApplication) {
22+
func applicationWillResignActive(_ application: UIApplication) {
2323
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
2424
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
2525
}
2626

27-
func applicationDidEnterBackground(application: UIApplication) {
27+
func applicationDidEnterBackground(_ application: UIApplication) {
2828
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
2929
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
3030
}
3131

32-
func applicationWillEnterForeground(application: UIApplication) {
32+
func applicationWillEnterForeground(_ application: UIApplication) {
3333
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
3434
}
3535

36-
func applicationDidBecomeActive(application: UIApplication) {
36+
func applicationDidBecomeActive(_ application: UIApplication) {
3737
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
3838
}
3939

40-
func applicationWillTerminate(application: UIApplication) {
40+
func applicationWillTerminate(_ application: UIApplication) {
4141
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
4242
}
4343

Example/NextGrowingTextView/ViewController.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ class ViewController: UIViewController {
3333
super.viewDidLoad()
3434
// Do any additional setup after loading the view, typically from a nib.
3535

36-
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil)
36+
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillShow(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
3737

38-
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.keyboardWillHide(_:)), name: UIKeyboardWillHideNotification, object: nil)
38+
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
3939

4040
self.growingTextView.layer.cornerRadius = 4
4141
self.growingTextView.backgroundColor = UIColor(white: 0.9, alpha: 1)
4242
self.growingTextView.textContainerInset = UIEdgeInsets(top: 16, left: 0, bottom: 4, right: 0)
43-
self.growingTextView.placeholderAttributedText = NSAttributedString(string: "Placeholder text",
43+
self.growingTextView.placeholderAttributedText = AttributedString(string: "Placeholder text",
4444
attributes: [NSFontAttributeName: self.growingTextView.font!,
45-
NSForegroundColorAttributeName: UIColor.grayColor()
45+
NSForegroundColorAttributeName: UIColor.gray()
4646
]
4747
)
4848
}
@@ -51,32 +51,32 @@ class ViewController: UIViewController {
5151
super.didReceiveMemoryWarning()
5252
// Dispose of any resources that can be recreated.
5353
}
54-
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
54+
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
5555
self.view.endEditing(true)
5656
}
5757

5858

59-
@IBAction func handleSendButton(sender: AnyObject) {
59+
@IBAction func handleSendButton(_ sender: AnyObject) {
6060
self.growingTextView.text = ""
6161
self.view.endEditing(true)
6262
}
6363

6464

65-
func keyboardWillHide(sender: NSNotification) {
66-
if let userInfo = sender.userInfo {
67-
if let _ = userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue.size.height {
65+
func keyboardWillHide(_ sender: Notification) {
66+
if let userInfo = (sender as NSNotification).userInfo {
67+
if let _ = userInfo[UIKeyboardFrameEndUserInfoKey]?.cgRectValue.size.height {
6868
//key point 0,
6969
self.inputContainerViewBottom.constant = 0
7070
//textViewBottomConstraint.constant = keyboardHeight
71-
UIView.animateWithDuration(0.25, animations: { () -> Void in self.view.layoutIfNeeded() })
71+
UIView.animate(withDuration: 0.25, animations: { () -> Void in self.view.layoutIfNeeded() })
7272
}
7373
}
7474
}
75-
func keyboardWillShow(sender: NSNotification) {
76-
if let userInfo = sender.userInfo {
77-
if let keyboardHeight = userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue.size.height {
75+
func keyboardWillShow(_ sender: Notification) {
76+
if let userInfo = (sender as NSNotification).userInfo {
77+
if let keyboardHeight = userInfo[UIKeyboardFrameEndUserInfoKey]?.cgRectValue.size.height {
7878
self.inputContainerViewBottom.constant = keyboardHeight
79-
UIView.animateWithDuration(0.25, animations: { () -> Void in
79+
UIView.animate(withDuration: 0.25, animations: { () -> Void in
8080
self.view.layoutIfNeeded()
8181
})
8282
}

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Tests/Tests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Tests: XCTestCase {
2121

2222
func testPerformanceExample() {
2323
// This is an example of a performance test case.
24-
self.measureBlock() {
24+
self.measure() {
2525
// Put the code you want to measure the time of here.
2626
}
2727
}

Pod/Classes/NextGrowingInternalTextView.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ internal class NextGrowingInternalTextView: UITextView {
3232
override init(frame: CGRect, textContainer: NSTextContainer?) {
3333
super.init(frame: frame, textContainer: textContainer)
3434

35-
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(NextGrowingInternalTextView.textDidChangeNotification(_ :)), name: UITextViewTextDidChangeNotification, object: self)
35+
NotificationCenter.default.addObserver(self, selector: #selector(NextGrowingInternalTextView.textDidChangeNotification(_ :)), name: NSNotification.Name.UITextViewTextDidChange, object: self)
3636
}
3737

3838
required init?(coder aDecoder: NSCoder) {
3939
fatalError("init(coder:) has not been implemented")
4040
}
4141

4242
deinit {
43-
NSNotificationCenter.defaultCenter().removeObserver(self)
43+
NotificationCenter.default.removeObserver(self)
4444
}
4545

4646
override var text: String! {
@@ -49,7 +49,7 @@ internal class NextGrowingInternalTextView: UITextView {
4949
}
5050
}
5151

52-
var placeholderAttributedText: NSAttributedString? {
52+
var placeholderAttributedText: AttributedString? {
5353
didSet {
5454
self.setNeedsDisplay()
5555
}
@@ -60,9 +60,9 @@ internal class NextGrowingInternalTextView: UITextView {
6060
self.setNeedsDisplay()
6161
}
6262

63-
override func drawRect(rect: CGRect) {
63+
override func draw(_ rect: CGRect) {
6464

65-
super.drawRect(rect)
65+
super.draw(rect)
6666

6767
guard self.displayPlaceholder == true else {
6868
return
@@ -77,7 +77,7 @@ internal class NextGrowingInternalTextView: UITextView {
7777
height: self.frame.size.height - (self.textContainerInset.top + self.textContainerInset.bottom))
7878

7979
let attributedString = self.placeholderAttributedText
80-
attributedString?.drawInRect(targetRect)
80+
attributedString?.draw(in: targetRect)
8181
}
8282

8383
// MARK: Private
@@ -90,7 +90,7 @@ internal class NextGrowingInternalTextView: UITextView {
9090
}
9191
}
9292

93-
private dynamic func textDidChangeNotification(notification: NSNotification) {
93+
private dynamic func textDidChangeNotification(_ notification: Notification) {
9494

9595
self.updatePlaceholder()
9696
}

Pod/Classes/NextGrowingTextView.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class NextGrowingTextView: UIScrollView {
3333

3434
public class Delegates {
3535
public var shouldChangeTextInRange: (range: NSRange, replacementText: String) -> Bool = { _ in true }
36-
public var shouldInteractWithURL: (URL: NSURL, inRange: NSRange) -> Bool = { _ in true }
36+
public var shouldInteractWithURL: (URL: URL, inRange: NSRange) -> Bool = { _ in true }
3737
public var shouldInteractWithTextAttachment: (textAttachment: NSTextAttachment, inRange: NSRange) -> Bool = { _ in true }
3838
public var textViewDidBeginEditing: (NextGrowingTextView) -> Void = { _ in }
3939
public var textViewDidChangeSelection: (NextGrowingTextView) -> Void = { _ in }
@@ -150,9 +150,9 @@ public class NextGrowingTextView: UIScrollView {
150150
private func setup() {
151151

152152
self.textView.delegate = self
153-
self.textView.scrollEnabled = false
154-
self.textView.font = UIFont.systemFontOfSize(16)
155-
self.textView.backgroundColor = UIColor.clearColor()
153+
self.textView.isScrollEnabled = false
154+
self.textView.font = UIFont.systemFont(ofSize: 16)
155+
self.textView.backgroundColor = UIColor.clear()
156156
self.addSubview(textView)
157157
self.minHeight = simulateHeight(1)
158158
self.maxNumberOfLines = 3
@@ -162,7 +162,7 @@ public class NextGrowingTextView: UIScrollView {
162162
return textView.sizeThatFits(CGSize(width: self.bounds.width, height: CGFloat.infinity))
163163
}
164164

165-
private func measureFrame(contentSize: CGSize) -> CGRect {
165+
private func measureFrame(_ contentSize: CGSize) -> CGRect {
166166

167167
let selfSize: CGSize
168168

@@ -221,13 +221,13 @@ public class NextGrowingTextView: UIScrollView {
221221
self.fitToScrollView()
222222
}
223223

224-
private func simulateHeight(line: Int) -> CGFloat {
224+
private func simulateHeight(_ line: Int) -> CGFloat {
225225

226226
let saveText = self.textView.text
227227
var newText = "-"
228228

229229
self.textView.delegate = nil
230-
self.textView.hidden = true
230+
self.textView.isHidden = true
231231

232232
for _ in 0..<line-1 {
233233
newText += "\n|W|"
@@ -238,7 +238,7 @@ public class NextGrowingTextView: UIScrollView {
238238
let height = self.measureTextViewSize().height
239239

240240
self.textView.text = saveText
241-
self.textView.hidden = false
241+
self.textView.isHidden = false
242242
self.textView.delegate = self
243243

244244
return height
@@ -254,7 +254,7 @@ extension NextGrowingTextView {
254254

255255
// MARK: TextView Extension
256256

257-
public var placeholderAttributedText: NSAttributedString? {
257+
public var placeholderAttributedText: AttributedString? {
258258
get {return self.textView.placeholderAttributedText }
259259
set {self.textView.placeholderAttributedText = newValue }
260260
}
@@ -303,16 +303,16 @@ extension NextGrowingTextView {
303303
}
304304

305305
public var selectable: Bool {
306-
get { return self.textView.selectable }
307-
set { self.textView.selectable = newValue }
306+
get { return self.textView.isSelectable }
307+
set { self.textView.isSelectable = newValue }
308308
}
309309

310310
public var allowsEditingTextAttributes: Bool {
311311
get { return self.allowsEditingTextAttributes }
312312
set { self.allowsEditingTextAttributes = newValue }
313313
}
314314

315-
public var attributedText: NSAttributedString! {
315+
public var attributedText: AttributedString! {
316316
get { return self.textView.attributedText }
317317
set {
318318
self.textView.attributedText = newValue
@@ -325,7 +325,7 @@ extension NextGrowingTextView {
325325
set { self.textView.typingAttributes = newValue }
326326
}
327327

328-
public func scrollRangeToVisible(range: NSRange) {
328+
public func scrollRangeToVisible(_ range: NSRange) {
329329
self.textView.scrollRangeToVisible(range)
330330
}
331331

@@ -393,39 +393,39 @@ extension NextGrowingTextView {
393393

394394
extension NextGrowingTextView: UITextViewDelegate {
395395

396-
public func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
396+
public func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
397397
return self.delegates.shouldChangeTextInRange(range: range, replacementText: text)
398398
}
399399

400-
public func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool {
400+
public func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
401401
return self.delegates.shouldInteractWithURL(URL: URL, inRange: characterRange)
402402
}
403403

404-
public func textView(textView: UITextView, shouldInteractWithTextAttachment textAttachment: NSTextAttachment, inRange characterRange: NSRange) -> Bool {
404+
public func textView(_ textView: UITextView, shouldInteractWith textAttachment: NSTextAttachment, in characterRange: NSRange) -> Bool {
405405
return self.delegates.shouldInteractWithTextAttachment(textAttachment: textAttachment, inRange: characterRange)
406406
}
407407

408-
public func textViewDidBeginEditing(textView: UITextView) {
408+
public func textViewDidBeginEditing(_ textView: UITextView) {
409409
self.delegates.textViewDidBeginEditing(self)
410410
}
411411

412-
public func textViewDidChangeSelection(textView: UITextView) {
412+
public func textViewDidChangeSelection(_ textView: UITextView) {
413413
self.delegates.textViewDidChangeSelection(self)
414414
}
415415

416-
public func textViewDidEndEditing(textView: UITextView) {
416+
public func textViewDidEndEditing(_ textView: UITextView) {
417417
self.delegates.textViewDidEndEditing(self)
418418
}
419419

420-
public func textViewShouldBeginEditing(textView: UITextView) -> Bool {
420+
public func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
421421
return self.delegates.textViewShouldBeginEditing(self)
422422
}
423423

424-
public func textViewShouldEndEditing(textView: UITextView) -> Bool {
424+
public func textViewShouldEndEditing(_ textView: UITextView) -> Bool {
425425
return self.delegates.textViewShouldEndEditing(self)
426426
}
427427

428-
public func textViewDidChange(textView: UITextView) {
428+
public func textViewDidChange(_ textView: UITextView) {
429429

430430
self.delegates.textViewDidChange(self)
431431

0 commit comments

Comments
 (0)