diff --git a/Example/MYTableViewManager/ViewController.swift b/Example/MYTableViewManager/ViewController.swift index f67af28..ea32a03 100644 --- a/Example/MYTableViewManager/ViewController.swift +++ b/Example/MYTableViewManager/ViewController.swift @@ -34,7 +34,7 @@ class ViewController: UIViewController { let cellmodels0 = (0..<2).map { [weak self] i -> MYCellModel in let title = "Section 0 : index \(i)" return CustomCellModel(title: title) { _ in - println("Did select new cell : \(i)") + print("Did select new cell : \(i)") self?.pushChildViewController() } } @@ -47,7 +47,7 @@ class ViewController: UIViewController { let cellmodels1 = titles.map { [weak self] title -> MYCellModel in let data = CustomCellModel(title: "Section 1: " + title) { _ in - println("Did select cell with title = \(title)") + print(")Did select cell with title = \(title)") self?.pushChildViewController() } data.dynamicHeightEnabled = true diff --git a/Source/Hakuba.swift b/Source/Hakuba.swift index 6fc183d..af37a57 100644 --- a/Source/Hakuba.swift +++ b/Source/Hakuba.swift @@ -83,7 +83,7 @@ public class Hakuba : NSObject { if let s = sections.my_get(index) { return s } - let length = index + 1 - sectionCount + //let length = index + 1 - sectionCount let newSections = (sectionCount...index).map { i -> MYSection in let ns = MYSection() @@ -142,7 +142,7 @@ public extension Hakuba { return self } - func slide(_ animation: MYAnimation = .None) -> Self { + func slide(animation: MYAnimation = .None) -> Self { // TODO : implementation tableView?.reloadData() insertedSectionsRange = (100, -1) @@ -373,8 +373,8 @@ extension Hakuba { public func scrollViewDidScroll(scrollView: UIScrollView) { delegate?.scrollViewDidScroll?(scrollView) - - if let indexPath = tableView?.indexPathsForVisibleRows()?.first as? NSIndexPath { + + if let indexPath = tableView?.indexPathsForVisibleRows?.first { if currentTopSection != indexPath.section { if let headerView = tableView?.headerViewForSection(currentTopSection) as? MYHeaderFooterView { headerView.didChangeFloatingState(false) diff --git a/Source/MYCommon.swift b/Source/MYCommon.swift index 2b61c74..339f2dc 100644 --- a/Source/MYCommon.swift +++ b/Source/MYCommon.swift @@ -12,7 +12,7 @@ public typealias MYSelectionHandler = (MYBaseViewProtocol) -> () public typealias MYAnimation = UITableViewRowAnimation public protocol MYBaseViewProtocol { - func emitSelectedEvent(MYBaseViewProtocol) + func emitSelectedEvent(_: MYBaseViewProtocol) } public protocol MYBaseViewDelegate : class { diff --git a/Source/MYExtension.swift b/Source/MYExtension.swift index fc12435..537bbb4 100644 --- a/Source/MYExtension.swift +++ b/Source/MYExtension.swift @@ -83,21 +83,14 @@ extension Array { let mIndex = max(0, index) return min(count, mIndex) } - - func my_indexOf(item: T) -> Int? { - if item is Element { - return find(unsafeBitCast(self, [T].self), item) - } - return nil - } - + func my_getSafeRange(range: Range) -> Range? { let start = max(0, range.startIndex) let end = min(count, range.endIndex) return start <= end ? Range(start: start, end: end) : nil } - func my_get(index: Int) -> T? { + func my_get(index: Int) -> Element? { return my_hasIndex(index) ? self[index] : nil } @@ -139,7 +132,7 @@ extension Array { } func my_each(exe: (Int, Element) -> ()) { - for (index, item) in enumerate(self) { + for (index, item) in enumerate() { exe(index, item) } } diff --git a/Source/MYHeaderFooterView.swift b/Source/MYHeaderFooterView.swift index 626b5e9..63174f5 100644 --- a/Source/MYHeaderFooterView.swift +++ b/Source/MYHeaderFooterView.swift @@ -34,16 +34,11 @@ public class MYHeaderFooterView : UITableViewHeaderFooterView, MYBaseViewProtoco private weak var delegate: MYBaseViewDelegate? public var selectable = true - public required init(coder aDecoder: NSCoder) { + public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setup() } - - public override init(frame: CGRect) { - super.init(frame: frame) - setup() - } - + public override init(reuseIdentifier: String?) { super.init(reuseIdentifier: reuseIdentifier) setup() @@ -77,21 +72,21 @@ public extension MYHeaderFooterView { // MARK - Touch events public extension MYHeaderFooterView { - override func touchesBegan(touches: Set, withEvent event: UIEvent) { + override func touchesBegan(touches: Set, withEvent event: UIEvent?) { super.touchesBegan(touches, withEvent: event) if selectable { highlight(false) } } - - override func touchesCancelled(touches: Set!, withEvent event: UIEvent!) { + + override func touchesCancelled(touches: Set?, withEvent event: UIEvent?) { super.touchesCancelled(touches, withEvent: event) if selectable { unhighlight(false) } } - - override func touchesEnded(touches: Set, withEvent event: UIEvent) { + + override func touchesEnded(touches: Set, withEvent event: UIEvent?) { super.touchesEnded(touches, withEvent: event) if selectable { emitSelectedEvent(self) diff --git a/Source/MYReloadTracker.swift b/Source/MYReloadTracker.swift index f15719f..940071d 100644 --- a/Source/MYReloadTracker.swift +++ b/Source/MYReloadTracker.swift @@ -50,7 +50,7 @@ class MYReloadTracker { originalIndexes.my_remove(range) for i in ri { var newIndexes: [Int] = [] - if removedIndexes.my_indexOf(i) == nil { + if removedIndexes.indexOf(i) == nil { newIndexes.append(i) } removedIndexes += newIndexes diff --git a/Source/MYSection.swift b/Source/MYSection.swift index 975ba2a..72ba2b8 100644 --- a/Source/MYSection.swift +++ b/Source/MYSection.swift @@ -138,14 +138,14 @@ public extension MYSection { } func remove(cellmodel: MYCellModel) -> Self { - if let index = find(items, cellmodel) { + if let index = items.indexOf(cellmodel) { return remove(index) } return self } // MARK - slide - func slide(_ animation: MYAnimation = .None) -> Self { + func slide(animation: MYAnimation = .None) -> Self { switch reloadTracker.state { case .Add: delegate?.insertRows(reloadTracker.getIndexPaths(index), animation: animation) diff --git a/Source/MYTableViewCell.swift b/Source/MYTableViewCell.swift index 0537331..470246c 100644 --- a/Source/MYTableViewCell.swift +++ b/Source/MYTableViewCell.swift @@ -31,7 +31,7 @@ public class MYCellModel : MYViewModel { self.height = height } - public func slide(_ animation: MYAnimation = .None) -> Self { + public func slide(animation: MYAnimation = .None) -> Self { delegate?.reloadView(row, section: section, animation: animation) return self } @@ -39,9 +39,9 @@ public class MYCellModel : MYViewModel { public class MYTableViewCell : UITableViewCell, MYBaseViewProtocol { private weak var delegate: MYBaseViewDelegate? - weak var cellModel: MYCellModel? - - public required init(coder aDecoder: NSCoder) { + public internal(set) weak var cellModel: MYCellModel? + + public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setup() }