Skip to content

Commit

Permalink
swiftlint
Browse files Browse the repository at this point in the history
  • Loading branch information
matsune committed Jan 13, 2019
1 parent 7272a70 commit 97fcff1
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 44 deletions.
6 changes: 3 additions & 3 deletions YMCalendar/Month/Cell/EventView/ReusableObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
20 changes: 10 additions & 10 deletions YMCalendar/Month/Cell/EventView/ReusableObjectQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -49,7 +49,7 @@ final internal class ReusableObjectQueue {
return object
}
}

func removeAll() {
reusableObjects.removeAll()
}
Expand Down
34 changes: 17 additions & 17 deletions YMCalendar/Month/Cell/EventView/YMEventStandardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
14 changes: 7 additions & 7 deletions YMCalendar/Month/Cell/EventView/YMEventView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion YMCalendar/Month/Cell/EventView/YMEventsRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -157,14 +157,14 @@ 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()
}
cell.backgroundColor = UIColor(cgColor: event.calendar.cgColor)
cell.title = event.title
return cell

}
}
6 changes: 3 additions & 3 deletions YMCalendar/Month/YMCalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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<T: YMEventView>(_ identifier: String, forEventAtIndex index: Int, date: Date) -> T? {
guard let cell = reuseQueue.dequeueReusableObjectWithIdentifier(identifier) as? T? else {
return nil
Expand Down

0 comments on commit 97fcff1

Please sign in to comment.