From 97fcff1db6f38d2be33afec8a2bae530f0c9d0cb Mon Sep 17 00:00:00 2001 From: Yuma Matsune Date: Sun, 13 Jan 2019 12:48:35 +0900 Subject: [PATCH] swiftlint --- .../Month/Cell/EventView/ReusableObject.swift | 6 ++-- .../Cell/EventView/ReusableObjectQueue.swift | 20 +++++------ .../Cell/EventView/YMEventStandardView.swift | 34 +++++++++---------- .../Month/Cell/EventView/YMEventView.swift | 14 ++++---- .../Cell/EventView/YMEventsRowView.swift | 2 +- .../YMCalendarEKViewController.swift | 6 ++-- YMCalendar/Month/YMCalendarView.swift | 6 ++-- 7 files changed, 44 insertions(+), 44 deletions(-) diff --git a/YMCalendar/Month/Cell/EventView/ReusableObject.swift b/YMCalendar/Month/Cell/EventView/ReusableObject.swift index ec80768..c98dafc 100755 --- a/YMCalendar/Month/Cell/EventView/ReusableObject.swift +++ b/YMCalendar/Month/Cell/EventView/ReusableObject.swift @@ -11,10 +11,10 @@ import Foundation /// ReusableObject will be reused for many times, such as UICollectionViewCell. /// This object can be registared and dequeued. public protocol ReusableObject: class { - + init() - + var reuseIdentifier: String { get set } - + func prepareForReuse() } diff --git a/YMCalendar/Month/Cell/EventView/ReusableObjectQueue.swift b/YMCalendar/Month/Cell/EventView/ReusableObjectQueue.swift index d562500..6e23ea1 100755 --- a/YMCalendar/Month/Cell/EventView/ReusableObjectQueue.swift +++ b/YMCalendar/Month/Cell/EventView/ReusableObjectQueue.swift @@ -10,17 +10,17 @@ import Foundation final internal class ReusableObjectQueue { typealias T = ReusableObject - - var reusableObjects: [String : T] = [:] - - var objectClasses: [String : T.Type] = [:] - + + var reusableObjects: [String: T] = [:] + + var objectClasses: [String: T.Type] = [:] + var totalCreated = 0 - + var count: Int { return reusableObjects.count } - + func registerClass(_ objectClass: T.Type?, forObjectWithReuseIdentifier identifier: String) { if let objClass = objectClass { objectClasses[identifier] = objClass @@ -29,11 +29,11 @@ final internal class ReusableObjectQueue { reusableObjects.removeValue(forKey: identifier) } } - + func enqueueReusableObject(_ object: T) { reusableObjects[object.reuseIdentifier] = object } - + func dequeueReusableObjectWithIdentifier(_ identifier: String) -> T? { if let object = reusableObjects[identifier] { reusableObjects.removeValue(forKey: identifier) @@ -49,7 +49,7 @@ final internal class ReusableObjectQueue { return object } } - + func removeAll() { reusableObjects.removeAll() } diff --git a/YMCalendar/Month/Cell/EventView/YMEventStandardView.swift b/YMCalendar/Month/Cell/EventView/YMEventStandardView.swift index f049bb9..a466b76 100755 --- a/YMCalendar/Month/Cell/EventView/YMEventStandardView.swift +++ b/YMCalendar/Month/Cell/EventView/YMEventStandardView.swift @@ -10,47 +10,47 @@ import Foundation import UIKit public class YMEventStandardView: YMEventView { - + private let kSpace: CGFloat = 2 - + public var title: String = "" - + public var textColor: UIColor = .white - + public var font: UIFont = .systemFont(ofSize: 12.0) - + public var attrString = NSMutableAttributedString() - + public var baselineOffset: Float = 0.0 - + override public func layoutSubviews() { super.layoutSubviews() setNeedsDisplay() } - + override public func prepareForReuse() { super.prepareForReuse() setNeedsDisplay() } - + private func redrawStringInRect(_ rect: CGRect) { let style = NSMutableParagraphStyle() style.lineBreakMode = .byClipping - + let attributedString = NSMutableAttributedString(string: title, attributes: [ - NSAttributedString.Key.font : font, - NSAttributedString.Key.paragraphStyle : style, - NSAttributedString.Key.foregroundColor : textColor, - NSAttributedString.Key.baselineOffset : baselineOffset]) - + NSAttributedString.Key.font: font, + NSAttributedString.Key.paragraphStyle: style, + NSAttributedString.Key.foregroundColor: textColor, + NSAttributedString.Key.baselineOffset: baselineOffset]) + attrString = attributedString } - + override public func draw(_ rect: CGRect) { let drawRect = rect.insetBy(dx: kSpace, dy: 0) redrawStringInRect(drawRect) - + attrString.draw(with: drawRect, options: [.truncatesLastVisibleLine, .usesLineFragmentOrigin], context: nil) } } diff --git a/YMCalendar/Month/Cell/EventView/YMEventView.swift b/YMCalendar/Month/Cell/EventView/YMEventView.swift index c94516d..7afca97 100755 --- a/YMCalendar/Month/Cell/EventView/YMEventView.swift +++ b/YMCalendar/Month/Cell/EventView/YMEventView.swift @@ -10,27 +10,27 @@ import Foundation import UIKit open class YMEventView: UIView, ReusableObject { - + public var reuseIdentifier: String = "" - + public var selected: Bool = false - + public var visibleHeight: CGFloat = 0 - + override public init(frame: CGRect) { super.init(frame: frame) commonInit() } - + required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) commonInit() } - + private func commonInit() { clipsToBounds = true } - + public func prepareForReuse() { selected = false } diff --git a/YMCalendar/Month/Cell/EventView/YMEventsRowView.swift b/YMCalendar/Month/Cell/EventView/YMEventsRowView.swift index 1af54f4..2cbea5d 100644 --- a/YMCalendar/Month/Cell/EventView/YMEventsRowView.swift +++ b/YMCalendar/Month/Cell/EventView/YMEventsRowView.swift @@ -95,7 +95,7 @@ final class YMEventsRowView: UIScrollView { } private let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:))) - + private func createEventView(range: NSRange, line: Int, indexPath: IndexPath) { if let cell = eventsRowDelegate?.eventsRowView(self, cellForEventAtIndexPath: indexPath) { cell.frame = rectForCell(range: range, line: line) diff --git a/YMCalendar/Month/ViewController/YMCalendarEKViewController.swift b/YMCalendar/Month/ViewController/YMCalendarEKViewController.swift index 615fc3a..286d5b3 100644 --- a/YMCalendar/Month/ViewController/YMCalendarEKViewController.swift +++ b/YMCalendar/Month/ViewController/YMCalendarEKViewController.swift @@ -38,7 +38,7 @@ open class YMCalendarEKViewController: YMCalendarViewController { calendarView.dataSource = self calendarView.registerClass(YMEventStandardView.self, forEventCellReuseIdentifier: YMEventStandardViewIdentifier) - + eventKitManager.checkEventStoreAccessForCalendar { [weak self] granted in if granted { self?.reloadEvents() @@ -157,7 +157,7 @@ extension YMCalendarEKViewController: YMCalendarDataSource { open func calendarView(_ view: YMCalendarView, eventViewForEventAtIndex index: Int, date: Date) -> YMEventView { let events = eventsAtDate(date) precondition(index <= events.count) - + let event = events[index] guard let cell = view.dequeueReusableCellWithIdentifier(YMEventStandardViewIdentifier, forEventAtIndex: index, date: date) as? YMEventStandardView else { fatalError() @@ -165,6 +165,6 @@ extension YMCalendarEKViewController: YMCalendarDataSource { cell.backgroundColor = UIColor(cgColor: event.calendar.cgColor) cell.title = event.title return cell - + } } diff --git a/YMCalendar/Month/YMCalendarView.swift b/YMCalendar/Month/YMCalendarView.swift index 8da4ec9..776ca08 100644 --- a/YMCalendar/Month/YMCalendarView.swift +++ b/YMCalendar/Month/YMCalendarView.swift @@ -12,7 +12,7 @@ import UIKit final public class YMCalendarView: UIView, YMCalendarAppearance { private lazy var collectionView: UICollectionView = createCollectionView() - + private var reuseQueue = ReusableObjectQueue() private lazy var layout: YMCalendarLayout = { @@ -301,11 +301,11 @@ extension YMCalendarView { extension YMCalendarView { // MARK: - Public - + public func registerClass(_ objectClass: ReusableObject.Type, forEventCellReuseIdentifier identifier: String) { reuseQueue.registerClass(objectClass, forObjectWithReuseIdentifier: identifier) } - + public func dequeueReusableCellWithIdentifier(_ identifier: String, forEventAtIndex index: Int, date: Date) -> T? { guard let cell = reuseQueue.dequeueReusableObjectWithIdentifier(identifier) as? T? else { return nil