diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 0000000..0b64914 --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,11 @@ +disabled_rules: # rule identifiers to exclude from running + - file_length + - force_cast + - function_body_length + - line_length + - todo + - type_body_length + - variable_name + - variable_name_min_length + - variable_name_max_length + - type_name diff --git a/Chatto/.swiftlint.yml b/Chatto/.swiftlint.yml deleted file mode 100644 index c02339f..0000000 --- a/Chatto/.swiftlint.yml +++ /dev/null @@ -1,11 +0,0 @@ -disabled_rules: # rule identifiers to exclude from running - - file_length - - force_cast - - function_body_length - - line_length - - todo - - type_body_length - - variable_name -included: # paths to include during linting. `--path` is ignored if present. takes precendence over `excluded`. - - Source -excluded: # paths to ignore during linting. overridden by `included`. \ No newline at end of file diff --git a/Chatto/.swiftlint.yml b/Chatto/.swiftlint.yml new file mode 120000 index 0000000..9e225e4 --- /dev/null +++ b/Chatto/.swiftlint.yml @@ -0,0 +1 @@ +../.swiftlint.yml \ No newline at end of file diff --git a/Chatto/Source/ChatController/AccessoryViewRevealer.swift b/Chatto/Source/ChatController/AccessoryViewRevealer.swift index 9d68cb4..4c41dea 100644 --- a/Chatto/Source/ChatController/AccessoryViewRevealer.swift +++ b/Chatto/Source/ChatController/AccessoryViewRevealer.swift @@ -52,7 +52,7 @@ class AccessoryViewRevealer: NSObject, UIGestureRecognizerDelegate { case .Ended, .Cancelled, .Failed: self.revealAccessoryView(atOffset: 0) default: - break; + break } } diff --git a/Chatto/Source/ChatController/ChatViewController+Changes.swift b/Chatto/Source/ChatController/ChatViewController+Changes.swift index e7424de..7c50936 100644 --- a/Chatto/Source/ChatController/ChatViewController+Changes.swift +++ b/Chatto/Source/ChatController/ChatViewController+Changes.swift @@ -202,8 +202,7 @@ extension ChatViewController: ChatDataSourceDelegateProtocol { let newDecoratedItems = self.chatItemsDecorator?.decorateItems(newItems) ?? newItems.map { DecoratedChatItem(chatItem: $0, decorationAttributes: nil) } let changes = Chatto.generateChanges( oldCollection: oldItems.map { $0 }, - newCollection: newDecoratedItems.map { $0.chatItem } - ) + newCollection: newDecoratedItems.map { $0.chatItem }) let layoutModel = self.createLayoutModel(newDecoratedItems, collectionViewWidth: collectionViewWidth) let updateModelClosure : () -> Void = { [weak self] in self?.layoutModel = layoutModel @@ -252,7 +251,7 @@ extension ChatViewController: ChatDataSourceDelegateProtocol { public func chatCollectionViewLayoutModel() -> ChatCollectionViewLayoutModel { if self.layoutModel.calculatedForWidth != self.collectionView.bounds.width { - self.layoutModel = self.createLayoutModel(self.decoratedChatItems, collectionViewWidth: self.collectionView.bounds.width); + self.layoutModel = self.createLayoutModel(self.decoratedChatItems, collectionViewWidth: self.collectionView.bounds.width) } return self.layoutModel diff --git a/Chatto/Source/ChatController/ChatViewController.swift b/Chatto/Source/ChatController/ChatViewController.swift index 4cf877e..c3f111e 100644 --- a/Chatto/Source/ChatController/ChatViewController.swift +++ b/Chatto/Source/ChatController/ChatViewController.swift @@ -81,7 +81,7 @@ public class ChatViewController: UIViewController, UICollectionViewDataSource, U } private func addCollectionView() { - self.collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: self.createCollectionViewLayout) + self.collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: self.createCollectionViewLayout) self.collectionView.contentInset = self.constants.defaultContentInsets self.collectionView.scrollIndicatorInsets = self.constants.defaultScrollIndicatorInsets self.collectionView.alwaysBounceVertical = true @@ -111,7 +111,7 @@ public class ChatViewController: UIViewController, UICollectionViewDataSource, U private var inputContainerBottomConstraint: NSLayoutConstraint! private func addInputViews() { - self.inputContainer = UIView(frame: CGRectZero) + self.inputContainer = UIView(frame: CGRect.zero) self.inputContainer.autoresizingMask = .None self.inputContainer.translatesAutoresizingMaskIntoConstraints = false self.view.addSubview(self.inputContainer) diff --git a/Chatto/Source/ChatController/KeyboardTracker.swift b/Chatto/Source/ChatController/KeyboardTracker.swift index 66ecedc..c8a6c47 100644 --- a/Chatto/Source/ChatController/KeyboardTracker.swift +++ b/Chatto/Source/ChatController/KeyboardTracker.swift @@ -134,12 +134,12 @@ class KeyboardTracker { let inputContainerHeight = self.inputContainer.bounds.height let trackerViewHeight = self.trackingView.bounds.height if trackerViewHeight != inputContainerHeight { - self.keyboardTrackerView.bounds = CGRect(origin: CGPointZero, size: CGSize(width: self.keyboardTrackerView.bounds.width, height: inputContainerHeight)) + self.keyboardTrackerView.bounds = CGRect(origin: CGPoint.zero, size: CGSize(width: self.keyboardTrackerView.bounds.width, height: inputContainerHeight)) } } private func layoutInputAtBottom() { - self.keyboardTrackerView.bounds = CGRect(origin: CGPointZero, size: CGSize(width: self.keyboardTrackerView.bounds.width, height: 0)) + self.keyboardTrackerView.bounds = CGRect(origin: CGPoint.zero, size: CGSize(width: self.keyboardTrackerView.bounds.width, height: 0)) self.inputContainerBottomConstraint.constant = 0 self.view.layoutIfNeeded() } @@ -154,7 +154,7 @@ class KeyboardTracker { private class KeyboardTrackingView: UIView { - var positionChangedCallback: (() -> Void)?; + var positionChangedCallback: (() -> Void)? var observedView: UIView? deinit { diff --git a/Chatto/Tests/Chat Items/BaseChatItemPresenterTests.swift b/Chatto/Tests/Chat Items/BaseChatItemPresenterTests.swift index 8f08e68..d91b62c 100644 --- a/Chatto/Tests/Chat Items/BaseChatItemPresenterTests.swift +++ b/Chatto/Tests/Chat Items/BaseChatItemPresenterTests.swift @@ -26,7 +26,7 @@ import XCTest @testable import Chatto class BaseChatItemPresenterTests: XCTestCase { - + var presenter: BaseChatItemPresenter! override func setUp() { diff --git a/Chatto/Tests/ChatController/ChatCollectionViewLayoutTests.swift b/Chatto/Tests/ChatController/ChatCollectionViewLayoutTests.swift index 9e66b81..38ef528 100644 --- a/Chatto/Tests/ChatController/ChatCollectionViewLayoutTests.swift +++ b/Chatto/Tests/ChatController/ChatCollectionViewLayoutTests.swift @@ -59,4 +59,4 @@ private func Atttributes(item item: Int, frame: CGRect) -> UICollectionViewLayou let attributes = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath) attributes.frame = frame return attributes -} \ No newline at end of file +} diff --git a/Chatto/Tests/ChatController/ChatViewControllerTestHelpers.swift b/Chatto/Tests/ChatController/ChatViewControllerTestHelpers.swift index c65063b..8f651bc 100644 --- a/Chatto/Tests/ChatController/ChatViewControllerTestHelpers.swift +++ b/Chatto/Tests/ChatController/ChatViewControllerTestHelpers.swift @@ -89,7 +89,7 @@ class FakePresenterBuilder: ChatItemPresenterBuilderProtocol { } func createPresenterWithChatItem(chatItem: ChatItemProtocol) -> ChatItemPresenterProtocol { - self.presentersCreatedCount++ + self.presentersCreatedCount += 1 return FakePresenter() } diff --git a/Chatto/Tests/ChatController/ChatViewControllerTests.swift b/Chatto/Tests/ChatController/ChatViewControllerTests.swift index 3a5c69d..fe171d1 100644 --- a/Chatto/Tests/ChatController/ChatViewControllerTests.swift +++ b/Chatto/Tests/ChatController/ChatViewControllerTests.swift @@ -100,7 +100,7 @@ class ChatViewControllerTests: XCTestCase { self.fakeDidAppearAndLayout(controller: controller) controller.updateQueue.addTask { (completion) -> Void in fakeDataSource.hasMorePrevious = true - controller.collectionView.contentOffset = CGPointZero + controller.collectionView.contentOffset = CGPoint.zero controller.scrollViewDidScrollToTop(controller.collectionView) completion() asyncExpectation.fulfill() @@ -185,7 +185,7 @@ class ChatViewControllerTests: XCTestCase { notificationCenter.postNotificationName(UIKeyboardWillShowNotification, object: self, userInfo: [UIKeyboardFrameEndUserInfoKey: NSValue(CGRect: CGRect(x: 0, y: 400, width: 400, height: 500))]) XCTAssertEqual(400, controller.view.convertRect(controller.chatInputView.bounds, fromView: controller.chatInputView).maxY) } - + func testThat_LayoutAdaptsWhenKeyboardIsHidden() { let controller = TesteableChatViewController() let notificationCenter = NSNotificationCenter() diff --git a/Chatto/Tests/ChatController/CollectionChangesTests.swift b/Chatto/Tests/ChatController/CollectionChangesTests.swift index 2227394..fe174d5 100644 --- a/Chatto/Tests/ChatController/CollectionChangesTests.swift +++ b/Chatto/Tests/ChatController/CollectionChangesTests.swift @@ -89,7 +89,7 @@ func Item(uid: String) -> UniqueIdentificable { return UniqueIdentificableItem(uid: uid) } -func Move(from: Int, to:Int) -> CollectionChangeMove { +func Move(from: Int, to: Int) -> CollectionChangeMove { return CollectionChangeMove(indexPathOld: NSIndexPath(forItem: from, inSection: 0), indexPathNew: NSIndexPath(forItem: to, inSection: 0)) } diff --git a/Chatto/Tests/ChatController/SerialTaskQueueTests.swift b/Chatto/Tests/ChatController/SerialTaskQueueTests.swift index a5ecc0f..c945edc 100644 --- a/Chatto/Tests/ChatController/SerialTaskQueueTests.swift +++ b/Chatto/Tests/ChatController/SerialTaskQueueTests.swift @@ -26,7 +26,7 @@ import XCTest @testable import Chatto class SerialTaskQueueTests: XCTestCase { - + func testThat_GivenIsFreshlyCreated_WhenNewTaskIsAdded_ThenTaskIsNotExecuted() { let queue = SerialTaskQueue() var executed = false diff --git a/ChattoAdditions/.swiftlint.yml b/ChattoAdditions/.swiftlint.yml deleted file mode 100644 index c02339f..0000000 --- a/ChattoAdditions/.swiftlint.yml +++ /dev/null @@ -1,11 +0,0 @@ -disabled_rules: # rule identifiers to exclude from running - - file_length - - force_cast - - function_body_length - - line_length - - todo - - type_body_length - - variable_name -included: # paths to include during linting. `--path` is ignored if present. takes precendence over `excluded`. - - Source -excluded: # paths to ignore during linting. overridden by `included`. \ No newline at end of file diff --git a/ChattoAdditions/.swiftlint.yml b/ChattoAdditions/.swiftlint.yml new file mode 120000 index 0000000..9e225e4 --- /dev/null +++ b/ChattoAdditions/.swiftlint.yml @@ -0,0 +1 @@ +../.swiftlint.yml \ No newline at end of file diff --git a/ChattoAdditions/Source/AnimationUtils.swift b/ChattoAdditions/Source/AnimationUtils.swift index 3ea0b87..d970338 100644 --- a/ChattoAdditions/Source/AnimationUtils.swift +++ b/ChattoAdditions/Source/AnimationUtils.swift @@ -28,8 +28,8 @@ public extension CABasicAnimation { animation.duration = duration animation.fromValue = 0 animation.toValue = 1 - animation.fillMode = kCAFillModeForwards; - animation.additive = false; + animation.fillMode = kCAFillModeForwards + animation.additive = false return animation } } diff --git a/ChattoAdditions/Source/Chat Items/BaseMessage/Views/BaseMessageCollectionViewCell.swift b/ChattoAdditions/Source/Chat Items/BaseMessage/Views/BaseMessageCollectionViewCell.swift index d461565..a89092f 100644 --- a/ChattoAdditions/Source/Chat Items/BaseMessage/Views/BaseMessageCollectionViewCell.swift +++ b/ChattoAdditions/Source/Chat Items/BaseMessage/Views/BaseMessageCollectionViewCell.swift @@ -197,13 +197,13 @@ public class BaseMessageCollectionViewCell { static func sizingCell() -> PhotoMessageCollectionViewCell { - let cell = PhotoMessageCollectionViewCell(frame: CGRectZero) + let cell = PhotoMessageCollectionViewCell(frame: CGRect.zero) cell.viewContext = .Sizing return cell } diff --git a/ChattoAdditions/Source/Chat Items/TextMessages/Views/TextBubbleView.swift b/ChattoAdditions/Source/Chat Items/TextMessages/Views/TextBubbleView.swift index 83bb48a..72566ba 100644 --- a/ChattoAdditions/Source/Chat Items/TextMessages/Views/TextBubbleView.swift +++ b/ChattoAdditions/Source/Chat Items/TextMessages/Views/TextBubbleView.swift @@ -194,9 +194,9 @@ public final class TextBubbleView: UIView, MaximumLayoutWidthSpecificable, Backg private final class TextBubbleLayoutModel { let layoutContext: LayoutContext - var textFrame: CGRect = CGRectZero - var bubbleFrame: CGRect = CGRectZero - var size: CGSize = CGSizeZero + var textFrame: CGRect = CGRect.zero + var bubbleFrame: CGRect = CGRect.zero + var size: CGSize = CGSize.zero init(layoutContext: LayoutContext) { self.layoutContext = layoutContext @@ -226,7 +226,7 @@ private final class TextBubbleLayoutModel { let maxTextWidth = self.layoutContext.preferredMaxLayoutWidth - textHorizontalInset let textSize = self.textSizeThatFitsWidth(maxTextWidth) let bubbleSize = textSize.bma_outsetBy(dx: textHorizontalInset, dy: self.layoutContext.textInsets.bma_verticalInset) - self.bubbleFrame = CGRect(origin: CGPointZero, size: bubbleSize) + self.bubbleFrame = CGRect(origin: CGPoint.zero, size: bubbleSize) self.textFrame = UIEdgeInsetsInsetRect(self.bubbleFrame, self.layoutContext.textInsets) self.size = bubbleSize } diff --git a/ChattoAdditions/Source/Chat Items/TextMessages/Views/TextMessageCollectionViewCell.swift b/ChattoAdditions/Source/Chat Items/TextMessages/Views/TextMessageCollectionViewCell.swift index 0010415..263cefc 100644 --- a/ChattoAdditions/Source/Chat Items/TextMessages/Views/TextMessageCollectionViewCell.swift +++ b/ChattoAdditions/Source/Chat Items/TextMessages/Views/TextMessageCollectionViewCell.swift @@ -29,7 +29,7 @@ public typealias TextMessageCollectionViewCellStyleProtocol = TextBubbleViewStyl public final class TextMessageCollectionViewCell: BaseMessageCollectionViewCell { public static func sizingCell() -> TextMessageCollectionViewCell { - let cell = TextMessageCollectionViewCell(frame: CGRectZero) + let cell = TextMessageCollectionViewCell(frame: CGRect.zero) cell.viewContext = .Sizing return cell } diff --git a/ChattoAdditions/Source/Input/ChatInputBar.swift b/ChattoAdditions/Source/Input/ChatInputBar.swift index 1967d43..b7c9795 100644 --- a/ChattoAdditions/Source/Input/ChatInputBar.swift +++ b/ChattoAdditions/Source/Input/ChatInputBar.swift @@ -50,7 +50,7 @@ public class ChatInputBar: ReusableXibView { class public func loadNib() -> ChatInputBar { let view = NSBundle(forClass: self).loadNibNamed(self.nibName(), owner: nil, options: nil).first as! ChatInputBar view.translatesAutoresizingMaskIntoConstraints = false - view.frame = CGRectZero + view.frame = CGRect.zero return view } @@ -212,7 +212,7 @@ class SingleViewContainerView: UIView { if let subview = self.subviews.first { return subview.intrinsicContentSize() } else { - return CGSizeZero + return CGSize.zero } } diff --git a/ChattoAdditions/Source/Input/ChatInputBarPresenter.swift b/ChattoAdditions/Source/Input/ChatInputBarPresenter.swift index a642453..e368af3 100644 --- a/ChattoAdditions/Source/Input/ChatInputBarPresenter.swift +++ b/ChattoAdditions/Source/Input/ChatInputBarPresenter.swift @@ -25,7 +25,7 @@ import UIKit @objc public class ChatInputBarPresenter: NSObject { - let chatInputView: ChatInputBar; + let chatInputView: ChatInputBar let chatInputItems: [ChatInputItemProtocol] public init(chatInputView: ChatInputBar, chatInputItems: [ChatInputItemProtocol]) { diff --git a/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift b/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift index 4feb3f2..83d4dd6 100644 --- a/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift +++ b/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift @@ -48,7 +48,7 @@ import Foundation public var selected = false { didSet { - self.internalTabView.selected = self.selected; + self.internalTabView.selected = self.selected if self.selected != oldValue { self.photosInputView.reload() } diff --git a/ChattoAdditions/Source/Input/Photos/PhotosInputView.swift b/ChattoAdditions/Source/Input/Photos/PhotosInputView.swift index 0e8e89f..1fc06d3 100644 --- a/ChattoAdditions/Source/Input/Photos/PhotosInputView.swift +++ b/ChattoAdditions/Source/Input/Photos/PhotosInputView.swift @@ -133,7 +133,7 @@ extension PhotosInputView: UICollectionViewDataSource { func configureCollectionView() { self.collectionViewLayout = UICollectionViewFlowLayout() - self.collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: self.collectionViewLayout) + self.collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: self.collectionViewLayout) self.collectionView.backgroundColor = UIColor.whiteColor() self.collectionView.translatesAutoresizingMaskIntoConstraints = false self.collectionView.registerClass(LiveCameraCell.self, forCellWithReuseIdentifier: "bar") diff --git a/ChattoAdditions/Source/Input/Photos/PhotosInputViewItemSizeCalculator.swift b/ChattoAdditions/Source/Input/Photos/PhotosInputViewItemSizeCalculator.swift index 4c75041..6fc8075 100644 --- a/ChattoAdditions/Source/Input/Photos/PhotosInputViewItemSizeCalculator.swift +++ b/ChattoAdditions/Source/Input/Photos/PhotosInputViewItemSizeCalculator.swift @@ -27,7 +27,7 @@ struct PhotosInputViewItemSizeCalculator { var interitemSpace: CGFloat = 0 func itemSizeForWidth(width: CGFloat, atIndex index: Int) -> CGSize { - let availableWidth = width - self.interitemSpace * CGFloat((self.itemsPerRow - 1)); + let availableWidth = width - self.interitemSpace * CGFloat((self.itemsPerRow - 1)) if availableWidth <= 0 { return CGSize.zero } @@ -37,7 +37,7 @@ struct PhotosInputViewItemSizeCalculator { let extraPixels = Int(availableWidth) % self.itemsPerRow let isItemWithExtraPixel = index % self.itemsPerRow < extraPixels if isItemWithExtraPixel { - itemWidth++ + itemWidth += 1 } return CGSize(width: itemWidth, height: itemHeigth) } diff --git a/ChattoAdditions/Source/Input/ReusableXibView.swift b/ChattoAdditions/Source/Input/ReusableXibView.swift index 96456e6..c48fba5 100644 --- a/ChattoAdditions/Source/Input/ReusableXibView.swift +++ b/ChattoAdditions/Source/Input/ReusableXibView.swift @@ -35,14 +35,14 @@ import UIKit override public func awakeAfterUsingCoder(aDecoder: NSCoder) -> AnyObject? { if self.subviews.count > 0 { - return self; + return self } let bundle = NSBundle(forClass: self.dynamicType) if let loadedView = bundle.loadNibNamed(self.dynamicType.nibName(), owner: nil, options: nil).first as! UIView? { loadedView.frame = frame loadedView.autoresizingMask = autoresizingMask - loadedView.translatesAutoresizingMaskIntoConstraints = translatesAutoresizingMaskIntoConstraints; + loadedView.translatesAutoresizingMaskIntoConstraints = translatesAutoresizingMaskIntoConstraints for constraint in constraints { let firstItem = constraint.firstItem === self ? loadedView : constraint.firstItem let secondItem = constraint.secondItem === self ? loadedView : constraint.secondItem @@ -55,7 +55,7 @@ import UIKit } class func nibName() -> String { - assert(false, "Must be overriden"); + assert(false, "Must be overriden") return "" } } diff --git a/ChattoAdditions/Source/Input/Text/TextChatInputItem.swift b/ChattoAdditions/Source/Input/Text/TextChatInputItem.swift index 26fc32b..0f04dae 100644 --- a/ChattoAdditions/Source/Input/Text/TextChatInputItem.swift +++ b/ChattoAdditions/Source/Input/Text/TextChatInputItem.swift @@ -38,7 +38,7 @@ import Foundation public var selected = false { didSet { - self.internalTabView.selected = self.selected; + self.internalTabView.selected = self.selected } } } diff --git a/ChattoAdditions/Source/Utils.swift b/ChattoAdditions/Source/Utils.swift index c0271b9..e0caa88 100644 --- a/ChattoAdditions/Source/Utils.swift +++ b/ChattoAdditions/Source/Utils.swift @@ -83,7 +83,7 @@ public extension CGSize { public extension CGRect { var bma_bounds: CGRect { - return CGRect(origin: CGPointZero, size: self.size) + return CGRect(origin: CGPoint.zero, size: self.size) } var bma_center: CGPoint { @@ -145,7 +145,7 @@ public extension UIEdgeInsets { public extension UIImage { public func bma_tintWithColor(color: UIColor) -> UIImage { - let rect = CGRect(origin: CGPointZero, size: self.size) + let rect = CGRect(origin: CGPoint.zero, size: self.size) UIGraphicsBeginImageContextWithOptions(rect.size, false, self.scale) let context = UIGraphicsGetCurrentContext() color.setFill() @@ -157,7 +157,7 @@ public extension UIImage { } public func bma_blendWithColor(color: UIColor) -> UIImage { - let rect = CGRect(origin: CGPointZero, size: self.size) + let rect = CGRect(origin: CGPoint.zero, size: self.size) UIGraphicsBeginImageContextWithOptions(rect.size, false, UIScreen.mainScreen().scale) let context = UIGraphicsGetCurrentContext() CGContextTranslateCTM(context, 0, rect.height) @@ -166,15 +166,15 @@ public extension UIImage { CGContextDrawImage(context, rect, self.CGImage) CGContextClipToMask(context, rect, self.CGImage) color.setFill() - CGContextAddRect(context, rect); - CGContextDrawPath(context, .Fill); + CGContextAddRect(context, rect) + CGContextDrawPath(context, .Fill) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image.resizableImageWithCapInsets(self.capInsets) } public static func bma_imageWithColor(color: UIColor, size: CGSize) -> UIImage { - let rect = CGRectMake(0, 0, size.width, size.height) + let rect = CGRect(origin: CGPoint.zero, size: size) UIGraphicsBeginImageContextWithOptions(size, false, 0) color.setFill() UIRectFill(rect) diff --git a/ChattoAdditions/Tests/Chat Items/BaseMessage/BaseMessagePresenterTests.swift b/ChattoAdditions/Tests/Chat Items/BaseMessage/BaseMessagePresenterTests.swift index d099256..ad5e450 100644 --- a/ChattoAdditions/Tests/Chat Items/BaseMessage/BaseMessagePresenterTests.swift +++ b/ChattoAdditions/Tests/Chat Items/BaseMessage/BaseMessagePresenterTests.swift @@ -44,21 +44,21 @@ class BaseMessagePresenterTests: XCTestCase { } func testThat_WhenCellIsTappedOnFailIcon_ThenInteractionHandlerHandlesEvent() { - let cell = PhotoMessageCollectionViewCell(frame: CGRectZero) + let cell = PhotoMessageCollectionViewCell(frame: CGRect.zero) self.presenter.configureCell(cell, decorationAttributes: self.decorationAttributes) cell.failedButtonTapped() XCTAssertTrue(self.interactionHandler.didHandleTapOnFailIcon) } func testThat_WhenCellIsTappedOnBubble_ThenInteractionHandlerHandlesEvent() { - let cell = PhotoMessageCollectionViewCell(frame: CGRectZero) + let cell = PhotoMessageCollectionViewCell(frame: CGRect.zero) self.presenter.configureCell(cell, decorationAttributes: self.decorationAttributes) cell.bubbleTapped(UITapGestureRecognizer()) XCTAssertTrue(self.interactionHandler.didHandleTapOnBubble) } func testThat_WhenCellIsLongPressedOnBubble_ThenInteractionHandlerHandlesEvent() { - let cell = PhotoMessageCollectionViewCell(frame: CGRectZero) + let cell = PhotoMessageCollectionViewCell(frame: CGRect.zero) self.presenter.configureCell(cell, decorationAttributes: self.decorationAttributes) cell.bubbleLongPressed() XCTAssertTrue(self.interactionHandler.didHandleLongPressOnBubble) diff --git a/ChattoAdditions/Tests/Chat Items/PhotoMessages/PhotoMessagePresenterTests.swift b/ChattoAdditions/Tests/Chat Items/PhotoMessages/PhotoMessagePresenterTests.swift index 042d844..01195fd 100644 --- a/ChattoAdditions/Tests/Chat Items/PhotoMessages/PhotoMessagePresenterTests.swift +++ b/ChattoAdditions/Tests/Chat Items/PhotoMessages/PhotoMessagePresenterTests.swift @@ -46,7 +46,7 @@ class PhotoMessagePresenterTests: XCTestCase, UICollectionViewDataSource { } func testThat_CellIsConfigured() { - let cell = PhotoMessageCollectionViewCell(frame: CGRectZero) + let cell = PhotoMessageCollectionViewCell(frame: CGRect.zero) self.presenter.configureCell(cell, decorationAttributes: self.decorationAttributes) XCTAssertEqual(self.testImage, cell.bubbleView.photoMessageViewModel.image.value) } @@ -56,7 +56,7 @@ class PhotoMessagePresenterTests: XCTestCase, UICollectionViewDataSource { } func testThat_RegistersAndDequeuesCells() { - let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: UICollectionViewFlowLayout()) + let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: UICollectionViewFlowLayout()) PhotoMessagePresenter.registerCells(collectionView) collectionView.dataSource = self collectionView.reloadData() diff --git a/ChattoAdditions/Tests/Chat Items/TextMessages/TextMessagePresenterTests.swift b/ChattoAdditions/Tests/Chat Items/TextMessages/TextMessagePresenterTests.swift index 7835c0d..c672001 100644 --- a/ChattoAdditions/Tests/Chat Items/TextMessages/TextMessagePresenterTests.swift +++ b/ChattoAdditions/Tests/Chat Items/TextMessages/TextMessagePresenterTests.swift @@ -42,7 +42,7 @@ class TextMessagePresenterTests: XCTestCase, UICollectionViewDataSource { func testThat_RegistersAndDequeuesCells() { - let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: UICollectionViewFlowLayout()) + let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: UICollectionViewFlowLayout()) TextMessagePresenter.registerCells(collectionView) collectionView.dataSource = self collectionView.reloadData() @@ -56,7 +56,7 @@ class TextMessagePresenterTests: XCTestCase, UICollectionViewDataSource { } func testThat_CellIsConfigured() { - let cell = TextMessageCollectionViewCell(frame: CGRectZero) + let cell = TextMessageCollectionViewCell(frame: CGRect.zero) self.presenter.configureCell(cell, decorationAttributes: self.decorationAttributes) XCTAssertEqual("Some text", cell.bubbleView.textMessageViewModel.text) } @@ -66,7 +66,7 @@ class TextMessagePresenterTests: XCTestCase, UICollectionViewDataSource { } func testThat_ShouldShowMenuReturnsTrue() { - let cell = TextMessageCollectionViewCell(frame: CGRectZero) + let cell = TextMessageCollectionViewCell(frame: CGRect.zero) self.presenter.cellWillBeShown(cell) // Needs to have a reference to the current cell before getting menu calls XCTAssertTrue(self.presenter.shouldShowMenu()) } diff --git a/ChattoAdditions/Tests/Input/ChatInputItemTests.swift b/ChattoAdditions/Tests/Input/ChatInputItemTests.swift index 1628bfd..7dd568c 100644 --- a/ChattoAdditions/Tests/Input/ChatInputItemTests.swift +++ b/ChattoAdditions/Tests/Input/ChatInputItemTests.swift @@ -30,7 +30,7 @@ class ChatInputItemTests: XCTestCase { @objc class MockInputItem: NSObject, ChatInputItemProtocol { - var selected = false; + var selected = false var presentationMode: ChatInputItemPresentationMode = .Keyboard var showsSendButton = false var inputView: UIView? = nil diff --git a/ChattoAdditions/Tests/Input/ChatInputManagerTests.swift b/ChattoAdditions/Tests/Input/ChatInputManagerTests.swift index 87e15ea..b8d7c7c 100644 --- a/ChattoAdditions/Tests/Input/ChatInputManagerTests.swift +++ b/ChattoAdditions/Tests/Input/ChatInputManagerTests.swift @@ -139,7 +139,7 @@ class ChatInputManagerTests: XCTestCase { self.presenter.inputBarSendButtonPressed(self.bar) XCTAssertEqual(itemThatHandledInput, 1) } - + // MARK: - Bar editing tests func testThat_GivenPresenterHasFocusedItem_WhenBarDidEndEditing_FocusedItemLostFocus() { let item = MockInputItem() diff --git a/ChattoApp/.swiftlint.yml b/ChattoApp/.swiftlint.yml deleted file mode 100644 index cb0669b..0000000 --- a/ChattoApp/.swiftlint.yml +++ /dev/null @@ -1,11 +0,0 @@ -disabled_rules: # rule identifiers to exclude from running - - file_length - - force_cast - - function_body_length - - line_length - - todo - - type_body_length - - variable_name -included: # paths to include during linting. `--path` is ignored if present. takes precendence over `excluded`. - - ChattoApp -excluded: # paths to ignore during linting. overridden by `included`. \ No newline at end of file diff --git a/ChattoApp/.swiftlint.yml b/ChattoApp/.swiftlint.yml new file mode 120000 index 0000000..9e225e4 --- /dev/null +++ b/ChattoApp/.swiftlint.yml @@ -0,0 +1 @@ +../.swiftlint.yml \ No newline at end of file diff --git a/ChattoApp/ChattoApp/DemoChatViewController.swift b/ChattoApp/ChattoApp/DemoChatViewController.swift index c2626cf..6af4188 100644 --- a/ChattoApp/ChattoApp/DemoChatViewController.swift +++ b/ChattoApp/ChattoApp/DemoChatViewController.swift @@ -44,7 +44,7 @@ class DemoChatViewController: ChatViewController { let image = UIImage(named: "bubble-incoming-tail-border", inBundle: NSBundle(forClass: self.dynamicType), compatibleWithTraitCollection: nil)?.bma_tintWithColor(UIColor.blueColor()) super.chatItemsDecorator = ChatItemsDemoDecorator() let addIncomingMessageButton = UIBarButtonItem(image: image, style: .Plain, target: self, action: "addRandomIncomingMessage") - self.navigationItem.rightBarButtonItem = addIncomingMessageButton; + self.navigationItem.rightBarButtonItem = addIncomingMessageButton } @objc diff --git a/ChattoApp/ChattoApp/FakeDataSource.swift b/ChattoApp/ChattoApp/FakeDataSource.swift index a6bc6e6..135857b 100644 --- a/ChattoApp/ChattoApp/FakeDataSource.swift +++ b/ChattoApp/ChattoApp/FakeDataSource.swift @@ -26,13 +26,14 @@ import Foundation import Chatto class FakeDataSource: ChatDataSourceProtocol { - var lastMessageId: Int = 0 + var nextMessageId: Int = 0 let preferredMaxWindowSize = 500 var slidingWindow: SlidingDataSource! init(count: Int, pageSize: Int) { self.slidingWindow = SlidingDataSource(count: count, pageSize: pageSize) { () -> ChatItemProtocol in - return FakeMessageFactory.createChatItem("\(self.lastMessageId++)") + defer { self.nextMessageId += 1 } + return FakeMessageFactory.createChatItem("\(self.nextMessageId)") } } @@ -76,7 +77,8 @@ class FakeDataSource: ChatDataSourceProtocol { } func addTextMessage(text: String) { - let uid = "\(self.lastMessageId++)" + let uid = "\(self.nextMessageId)" + self.nextMessageId += 1 let message = createTextMessageModel(uid, text: text, isIncoming: false) self.messageSender.sendMessage(message) self.slidingWindow.insertItem(message, position: .Bottom) @@ -84,7 +86,8 @@ class FakeDataSource: ChatDataSourceProtocol { } func addPhotoMessage(image: UIImage) { - let uid = "\(self.lastMessageId++)" + let uid = "\(self.nextMessageId)" + self.nextMessageId += 1 let message = createPhotoMessageModel(uid, image: image, size: image.size, isIncoming: false) self.messageSender.sendMessage(message) self.slidingWindow.insertItem(message, position: .Bottom) @@ -92,7 +95,8 @@ class FakeDataSource: ChatDataSourceProtocol { } func addRandomIncomingMessage() { - let message = FakeMessageFactory.createChatItem("\(self.lastMessageId++)", isIncoming: true) + let message = FakeMessageFactory.createChatItem("\(self.nextMessageId)", isIncoming: true) + self.nextMessageId += 1 self.slidingWindow.insertItem(message, position: .Bottom) self.delegate?.chatDataSourceDidUpdate(self) } diff --git a/ChattoApp/ChattoApp/SlidingDatasSource.swift b/ChattoApp/ChattoApp/SlidingDatasSource.swift index 699bcc6..20f7a2c 100644 --- a/ChattoApp/ChattoApp/SlidingDatasSource.swift +++ b/ChattoApp/ChattoApp/SlidingDatasSource.swift @@ -72,15 +72,15 @@ public class SlidingDataSource { if position == .Top { self.items.insert(item, atIndex: 0) let shouldExpandWindow = self.itemsOffset == self.windowOffset - self.itemsOffset-- + self.itemsOffset -= 1 if shouldExpandWindow { - self.windowOffset-- - self.windowCount++ + self.windowOffset -= 1 + self.windowCount += 1 } } else { let shouldExpandWindow = self.itemsOffset + self.items.count == self.windowOffset + self.windowCount if shouldExpandWindow { - self.windowCount++ + self.windowCount += 1 } self.items.append(item) } diff --git a/ChattoApp/ChattoApp/Source/Custom items/Sending status/SendingStatusPresenter.swift b/ChattoApp/ChattoApp/Source/Custom items/Sending status/SendingStatusPresenter.swift index 8b9b07a..ea29cee 100644 --- a/ChattoApp/ChattoApp/Source/Custom items/Sending status/SendingStatusPresenter.swift +++ b/ChattoApp/ChattoApp/Source/Custom items/Sending status/SendingStatusPresenter.swift @@ -90,7 +90,7 @@ class SendingStatusPresenter: ChatItemPresenterProtocol { ] statusCell.text = NSAttributedString( string: self.statusText(), - attributes: attrs); + attributes: attrs) } func statusText() -> String { diff --git a/ChattoApp/ChattoApp/Source/FakeMessageFactory.swift b/ChattoApp/ChattoApp/Source/FakeMessageFactory.swift index 1eb64d3..b03da2c 100644 --- a/ChattoApp/ChattoApp/Source/FakeMessageFactory.swift +++ b/ChattoApp/ChattoApp/Source/FakeMessageFactory.swift @@ -79,7 +79,7 @@ class FakeMessageFactory { } class func createPhotoMessageModel(uid: String, isIncoming: Bool) -> PhotoMessageModel { - var imageSize = CGSizeZero + var imageSize = CGSize.zero switch arc4random_uniform(100) % 3 { case 0: imageSize = CGSize(width: 400, height: 300) diff --git a/ChattoApp/ChattoAppTests/SlidingDataSourceTests.swift b/ChattoApp/ChattoAppTests/SlidingDataSourceTests.swift index 6715088..77dbf5d 100644 --- a/ChattoApp/ChattoAppTests/SlidingDataSourceTests.swift +++ b/ChattoApp/ChattoAppTests/SlidingDataSourceTests.swift @@ -33,7 +33,8 @@ class SlidingDataSourceTests: XCTestCase { return "\(id)" } let dataSource = SlidingDataSource(count: 10000, pageSize: 50) { () -> String in - return "\(uid++)" + defer { uid += 1 } + return "\(uid)" } XCTAssertEqual(expectedArray, dataSource.itemsInWindow) @@ -47,7 +48,8 @@ class SlidingDataSourceTests: XCTestCase { return "\(id)" } let dataSource = SlidingDataSource(count: 10, pageSize: 50) { () -> String in - return "\(uid++)" + defer { uid += 1 } + return "\(uid)" } XCTAssertEqual(expectedArray, dataSource.itemsInWindow) @@ -58,7 +60,8 @@ class SlidingDataSourceTests: XCTestCase { func testThat_WhenCountIsZero_ThenInitializesCorrectly() { var uid = 0 let dataSource = SlidingDataSource(count: 0, pageSize: 50) { () -> String in - return "\(uid++)" + defer { uid += 1 } + return "\(uid)" } XCTAssertEqual([], dataSource.itemsInWindow) XCTAssertFalse(dataSource.hasPrevious()) @@ -72,7 +75,8 @@ class SlidingDataSourceTests: XCTestCase { return "\(id)" } let dataSource = SlidingDataSource(count: 10000, pageSize: 50) { (id) -> String in - return "\(uid++)" + defer { uid += 1 } + return "\(uid)" } dataSource.loadPrevious() @@ -89,7 +93,8 @@ class SlidingDataSourceTests: XCTestCase { } let dataSource = SlidingDataSource(count: 10000, pageSize: 50) { (id) -> String in - return "\(uid++)" + defer { uid += 1 } + return "\(uid)" } for _ in 0..<10 { @@ -108,7 +113,8 @@ class SlidingDataSourceTests: XCTestCase { } let dataSource = SlidingDataSource(count: 10000, pageSize: 50) { (id) -> String in - return "\(uid++)" + defer { uid += 1 } + return "\(uid)" } dataSource.loadPrevious() dataSource.loadPrevious() @@ -128,7 +134,8 @@ class SlidingDataSourceTests: XCTestCase { expectedArray.append("test") let dataSource = SlidingDataSource(count: 10000, pageSize: 50) { (id) -> String in - return "\(uid++)" + defer { uid += 1 } + return "\(uid)" } for _ in 0..<10 { @@ -154,7 +161,8 @@ class SlidingDataSourceTests: XCTestCase { return "\(id)" } let dataSource = SlidingDataSource(count: 52, pageSize: 50) { (id) -> String in - return "\(uid++)" + defer { uid += 1 } + return "\(uid)" } dataSource.loadPrevious() diff --git a/ChattoApp/ChattoAppUITests/ChattoAppUITests.swift b/ChattoApp/ChattoAppUITests/ChattoAppUITests.swift index 8e7653b..0621146 100644 --- a/ChattoApp/ChattoAppUITests/ChattoAppUITests.swift +++ b/ChattoApp/ChattoAppUITests/ChattoAppUITests.swift @@ -25,12 +25,12 @@ import XCTest class ChattoAppUITests: XCTestCase { - + override func setUp() { super.setUp() - + // Put setup code here. This method is called before the invocation of each test method in the class. - + // In UI tests it is usually best to stop immediately when a failure occurs. continueAfterFailure = false // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. @@ -42,15 +42,15 @@ class ChattoAppUITests: XCTestCase { // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. } - + 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() { // Use recording to get started writing UI tests. // Use XCTAssert and related functions to verify your tests produce the correct results. } - + }