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

SwiftLint #17

Closed
wants to merge 12 commits into from
Closed
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
4 changes: 4 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
included:
- MessageViewController
- MessageViewControllerTests
- Examples
15 changes: 15 additions & 0 deletions Examples/Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
29B98214201E738F0002DA39 /* Resources */,
8D226DA12211905BC93F2571 /* [CP] Embed Pods Frameworks */,
EE524A12456D75F342514EA8 /* [CP] Copy Pods Resources */,
5560190E20259DAC00E8A9E5 /* SwiftLint */,
);
buildRules = (
);
Expand Down Expand Up @@ -159,6 +160,20 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
5560190E20259DAC00E8A9E5 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = SwiftLint;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint --strict\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
};
8D226DA12211905BC93F2571 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
30 changes: 19 additions & 11 deletions Examples/Examples/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,42 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// 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.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
// 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.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games
// should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// 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.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
// 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.
// If your application supports background execution, this method is called instead of applicationWillTerminate:
// when the user quits.
}

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

func applicationDidBecomeActive(_ application: UIApplication) {
// 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.
// 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.
}

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


}

21 changes: 16 additions & 5 deletions Examples/Examples/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import UIKit
import MessageViewController

class ViewController: MessageViewController, UITableViewDataSource, UITableViewDelegate, MessageAutocompleteControllerDelegate {
class ViewController: MessageViewController {

// swiftlint:disable:next line_length
var data = "Lorem ipsum dolor sit amet|consectetur adipiscing elit|sed do eiusmod|tempor incididunt|ut labore et dolore|magna aliqua| Ut enim ad minim|veniam, quis nostrud|exercitation ullamco|laboris nisi ut aliquip|ex ea commodo consequat|Duis aute|irure dolor in reprehenderit|in voluptate|velit esse cillum|dolore eu|fugiat nulla pariatur|Excepteur sint occaecat|cupidatat non proident|sunt in culpa|qui officia|deserunt|mollit anim id est laborum"
.components(separatedBy: "|")
let users = ["rnystrom", "BasThomas", "jessesquires", "Sherlouk"]
Expand Down Expand Up @@ -53,8 +54,11 @@ class ViewController: MessageViewController, UITableViewDataSource, UITableViewD
animated: true
)
}
}

// MARK: UITableViewDataSource

// MARK: UITableViewDataSource
extension ViewController: UITableViewDataSource {

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableView === self.tableView
Expand All @@ -72,7 +76,11 @@ class ViewController: MessageViewController, UITableViewDataSource, UITableViewD
return cell
}

// MARK: UITableViewDelegate
}

// MARK: UITableViewDelegate

extension ViewController: UITableViewDelegate {

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
Expand All @@ -81,12 +89,15 @@ class ViewController: MessageViewController, UITableViewDataSource, UITableViewD
}
}

// MARK: MessageAutocompleteControllerDelegate
}

// MARK: MessageAutocompleteControllerDelegate

extension ViewController: MessageAutocompleteControllerDelegate {

func didFind(controller: MessageAutocompleteController, prefix: String, word: String) {
autocompleteUsers = users.filter { word.isEmpty || $0.lowercased().contains(word.lowercased()) }
controller.show(true)
}

}

18 changes: 18 additions & 0 deletions MessageViewController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
290482071FED90070053978C /* Frameworks */,
290482081FED90070053978C /* Headers */,
290482091FED90070053978C /* Resources */,
5560190F20259E6800E8A9E5 /* SwiftLint */,
);
buildRules = (
);
Expand Down Expand Up @@ -229,6 +230,23 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
5560190F20259E6800E8A9E5 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = SwiftLint;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint --strict\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
290482061FED90070053978C /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
17 changes: 5 additions & 12 deletions MessageViewController/MessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public final class MessageView: UIView, MessageTextViewListener {

internal weak var delegate: MessageViewDelegate?
internal let button = UIButton()
internal let UITextViewContentSizeKeyPath = #keyPath(UITextView.contentSize)
internal let topBorderLayer = CALayer()
internal var contentView: UIView?
internal var buttonAction: Selector?
Expand All @@ -32,7 +31,9 @@ public final class MessageView: UIView, MessageTextViewListener {
textView.contentInset = .zero
textView.textContainerInset = .zero
textView.backgroundColor = .clear
textView.addObserver(self, forKeyPath: UITextViewContentSizeKeyPath, options: [.new], context: nil)
textViewContentSizeObservation = textView.observe(\.contentSize, options: [.new]) { [weak self] (_, _) in
self?.textViewContentSizeDidChange()
}
textView.font = .systemFont(ofSize: UIFont.systemFontSize)
textView.add(listener: self)

Expand All @@ -58,10 +59,6 @@ public final class MessageView: UIView, MessageTextViewListener {
fatalError("init(coder:) has not been implemented")
}

deinit {
textView.removeObserver(self, forKeyPath: UITextViewContentSizeKeyPath)
}

// MARK: Public API

public var font: UIFont? {
Expand Down Expand Up @@ -188,12 +185,6 @@ public final class MessageView: UIView, MessageTextViewListener {
)
}

public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == UITextViewContentSizeKeyPath {
textViewContentSizeDidChange()
}
}

public override func resignFirstResponder() -> Bool {
return textView.resignFirstResponder()
}
Expand Down Expand Up @@ -231,6 +222,8 @@ public final class MessageView: UIView, MessageTextViewListener {
textView.alwaysBounceVertical = textView.contentSize.height > maxHeight
}

private var textViewContentSizeObservation: NSKeyValueObservation?

// MARK: MessageTextViewListener

public func didChange(textView: MessageTextView) {
Expand Down
37 changes: 31 additions & 6 deletions MessageViewController/MessageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,36 @@ open class MessageViewController: UIViewController, MessageAutocompleteControlle
messageAutocompleteController.layoutDelegate = self

let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
notificationCenter.addObserver(self, selector: #selector(keyboardDidShow(notification:)), name: NSNotification.Name.UIKeyboardDidShow, object: nil)
notificationCenter.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
notificationCenter.addObserver(self, selector: #selector(keyboardDidHide(notification:)), name: NSNotification.Name.UIKeyboardDidHide, object: nil)
notificationCenter.addObserver(self, selector: #selector(appWillResignActive(notification:)), name: NSNotification.Name.UIApplicationWillResignActive, object: nil)
notificationCenter.addObserver(
self,
selector: #selector(keyboardWillShow(notification:)),
name: NSNotification.Name.UIKeyboardWillShow,
object: nil
)
notificationCenter.addObserver(
self,
selector: #selector(keyboardDidShow(notification:)),
name: NSNotification.Name.UIKeyboardDidShow,
object: nil
)
notificationCenter.addObserver(
self,
selector: #selector(keyboardWillHide(notification:)),
name: NSNotification.Name.UIKeyboardWillHide,
object: nil
)
notificationCenter.addObserver(
self,
selector: #selector(keyboardDidHide(notification:)),
name: NSNotification.Name.UIKeyboardDidHide,
object: nil
)
notificationCenter.addObserver(
self,
selector: #selector(appWillResignActive(notification:)),
name: NSNotification.Name.UIApplicationWillResignActive,
object: nil
)
}

internal var safeAreaAdditionalHeight: CGFloat {
Expand Down Expand Up @@ -220,7 +245,7 @@ open class MessageViewController: UIViewController, MessageAutocompleteControlle
guard gesture.state == .changed else { return }
let location = gesture.location(in: view)
if messageView.frame.contains(location) {
let _ = messageView.resignFirstResponder()
_ = messageView.resignFirstResponder()
}
}

Expand Down
2 changes: 1 addition & 1 deletion MessageViewController/UITextView+Prefixes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit

internal extension UITextView {

// swiftlint:disable:next large_tuple
func find(prefixes: Set<String>) -> (prefix: String, word: String, range: NSRange)? {
guard prefixes.count > 0,
let result = wordAtCaret,
Expand Down Expand Up @@ -43,4 +44,3 @@ internal extension UITextView {
}

}

4 changes: 2 additions & 2 deletions MessageViewController/UIView+iOS11.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import UIKit

internal extension UIView {

// swiftlint:disable:next identifier_name
var util_safeAreaInsets: UIEdgeInsets {
if #available(iOS 11.0, *) {
return safeAreaInsets
Expand All @@ -20,7 +20,7 @@ internal extension UIView {
}

internal extension UIScrollView {

// swiftlint:disable:next identifier_name
var util_adjustedContentInset: UIEdgeInsets {
if #available(iOS 11.0, *) {
return adjustedContentInset
Expand Down
10 changes: 5 additions & 5 deletions MessageViewControllerTests/MessageViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@
import XCTest

class MessageViewControllerTests: XCTestCase {

override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}

func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}
Loading