Skip to content

Commit 9112ef5

Browse files
committed
Swift3
1 parent d338070 commit 9112ef5

File tree

7 files changed

+237
-221
lines changed

7 files changed

+237
-221
lines changed

Example/NextGrowingTextView.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,12 @@
215215
TargetAttributes = {
216216
607FACCF1AFB9204008FA782 = {
217217
CreatedOnToolsVersion = 6.3.1;
218+
LastSwiftMigration = 0800;
218219
};
219220
607FACE41AFB9204008FA782 = {
220221
CreatedOnToolsVersion = 6.3.1;
221222
DevelopmentTeam = KU2QEJ9K3Z;
223+
LastSwiftMigration = 0800;
222224
TestTargetID = 607FACCF1AFB9204008FA782;
223225
};
224226
};
@@ -495,6 +497,7 @@
495497
MODULE_NAME = ExampleApp;
496498
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
497499
PRODUCT_NAME = "$(TARGET_NAME)";
500+
SWIFT_VERSION = 3.0;
498501
};
499502
name = Debug;
500503
};
@@ -508,6 +511,7 @@
508511
MODULE_NAME = ExampleApp;
509512
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
510513
PRODUCT_NAME = "$(TARGET_NAME)";
514+
SWIFT_VERSION = 3.0;
511515
};
512516
name = Release;
513517
};
@@ -531,6 +535,7 @@
531535
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
532536
PRODUCT_NAME = "$(TARGET_NAME)";
533537
PROVISIONING_PROFILE = "";
538+
SWIFT_VERSION = 3.0;
534539
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/NextGrowingTextView_Example.app/NextGrowingTextView_Example";
535540
};
536541
name = Debug;
@@ -551,6 +556,7 @@
551556
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
552557
PRODUCT_NAME = "$(TARGET_NAME)";
553558
PROVISIONING_PROFILE = "";
559+
SWIFT_VERSION = 3.0;
554560
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/NextGrowingTextView_Example.app/NextGrowingTextView_Example";
555561
};
556562
name = Release;

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: [UIApplicationLaunchOptionsKey: Any]?) -> 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: 27 additions & 32 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)
39-
40-
self.growingTextView.layer.cornerRadius = 4
41-
self.growingTextView.backgroundColor = UIColor(white: 0.9, alpha: 1)
42-
self.growingTextView.textContainerInset = UIEdgeInsets(top: 16, left: 0, bottom: 4, right: 0)
43-
self.growingTextView.placeholderAttributedText = NSAttributedString(string: "Placeholder text",
44-
attributes: [NSFontAttributeName: self.growingTextView.font!,
45-
NSForegroundColorAttributeName: UIColor.grayColor()
38+
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
39+
40+
growingTextView.layer.cornerRadius = 4
41+
growingTextView.backgroundColor = UIColor(white: 0.9, alpha: 1)
42+
growingTextView.textContainerInset = UIEdgeInsets(top: 16, left: 0, bottom: 4, right: 0)
43+
growingTextView.placeholderAttributedText = NSAttributedString(string: "Placeholder text",
44+
attributes: [NSFontAttributeName: growingTextView.font!,
45+
NSForegroundColorAttributeName: UIColor.gray
4646
]
4747
)
4848
}
@@ -51,36 +51,31 @@ 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?) {
55-
self.view.endEditing(true)
54+
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
55+
view.endEditing(true)
5656
}
5757

58-
59-
@IBAction func handleSendButton(sender: AnyObject) {
60-
self.growingTextView.text = ""
61-
self.view.endEditing(true)
58+
@IBAction func handleSendButton(_ sender: AnyObject) {
59+
growingTextView.text = ""
60+
view.endEditing(true)
6261
}
6362

6463

65-
func keyboardWillHide(sender: NSNotification) {
66-
if let userInfo = sender.userInfo {
67-
if let _ = userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue.size.height {
68-
//key point 0,
69-
self.inputContainerViewBottom.constant = 0
70-
//textViewBottomConstraint.constant = keyboardHeight
71-
UIView.animateWithDuration(0.25, animations: { () -> Void in self.view.layoutIfNeeded() })
72-
}
73-
}
64+
func keyboardWillHide(_ sender: Notification) {
65+
66+
//key point 0,
67+
inputContainerViewBottom.constant = 0
68+
//textViewBottomConstraint.constant = keyboardHeight
69+
UIView.animate(withDuration: 0.25, animations: { () -> Void in self.view.layoutIfNeeded() })
7470
}
75-
func keyboardWillShow(sender: NSNotification) {
76-
if let userInfo = sender.userInfo {
77-
if let keyboardHeight = userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue.size.height {
78-
self.inputContainerViewBottom.constant = keyboardHeight
79-
UIView.animateWithDuration(0.25, animations: { () -> Void in
80-
self.view.layoutIfNeeded()
81-
})
82-
}
71+
func keyboardWillShow(_ sender: Notification) {
72+
guard let keyboardHeight = (sender.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.size.height else {
73+
return
8374
}
75+
inputContainerViewBottom.constant = keyboardHeight
76+
UIView.animate(withDuration: 0.25, animations: { () -> Void in
77+
self.view.layoutIfNeeded()
78+
})
8479
}
8580
}
8681

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 17 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: 8 additions & 8 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! {
@@ -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,25 +77,25 @@ 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
8484

85-
private var displayPlaceholder: Bool = true {
85+
fileprivate var displayPlaceholder: Bool = true {
8686
didSet {
8787
if oldValue != self.displayPlaceholder {
8888
self.setNeedsDisplay()
8989
}
9090
}
9191
}
9292

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

9595
self.updatePlaceholder()
9696
}
9797

98-
private func updatePlaceholder() {
98+
fileprivate func updatePlaceholder() {
9999
self.displayPlaceholder = self.text.characters.count == 0
100100
}
101101
}

0 commit comments

Comments
 (0)