From 917f1697bbd6344009842e41b48945e559b9faad Mon Sep 17 00:00:00 2001 From: Le Van Nghia Date: Wed, 11 Feb 2015 21:43:02 +0900 Subject: [PATCH] refactoring --- Source/MYBaseClasses.swift | 2 +- Source/MYHeaderFooterView.swift | 16 ++++++++-------- Source/MYLabel.swift | 4 ++-- Source/MYTableViewCell.swift | 8 ++++---- Source/MYTableViewManager.swift | 19 ++----------------- 5 files changed, 17 insertions(+), 32 deletions(-) diff --git a/Source/MYBaseClasses.swift b/Source/MYBaseClasses.swift index 3525045..62ba923 100644 --- a/Source/MYBaseClasses.swift +++ b/Source/MYBaseClasses.swift @@ -29,7 +29,7 @@ public class MYBaseViewData : NSObject, MYBaseViewDelegate { weak var delegate: MYBaseViewDataDelegate? var userData: AnyObject? - init(userData: AnyObject? = nil, selectionHandler: MYSelectionHandler?) { + public init(userData: AnyObject? = nil, selectionHandler: MYSelectionHandler?) { self.userData = userData self.action = selectionHandler } diff --git a/Source/MYHeaderFooterView.swift b/Source/MYHeaderFooterView.swift index 58eadc0..b6c733d 100644 --- a/Source/MYHeaderFooterView.swift +++ b/Source/MYHeaderFooterView.swift @@ -13,7 +13,7 @@ public class MYHeaderFooterViewData : MYBaseViewData { var viewHeight: CGFloat = 44 var isEnabled = true - init(viewClass: AnyClass, userData: AnyObject?, selectionHandler: MYSelectionHandler? = nil) { + public init(viewClass: AnyClass, userData: AnyObject?, selectionHandler: MYSelectionHandler? = nil) { self.identifier = String.className(viewClass) super.init(userData: userData, selectionHandler: selectionHandler) } @@ -23,7 +23,7 @@ public class MYHeaderFooterView : UITableViewHeaderFooterView, MYBaseViewProtoco class var identifier: String { return String.className(self) } private weak var delegate: MYBaseViewDelegate? - override init() { + public override init() { super.init() setup() } @@ -33,20 +33,20 @@ public class MYHeaderFooterView : UITableViewHeaderFooterView, MYBaseViewProtoco setup() } - override init(frame: CGRect) { + public override init(frame: CGRect) { super.init(frame: frame) setup() } - override init(reuseIdentifier: String?) { + public override init(reuseIdentifier: String?) { super.init(reuseIdentifier: reuseIdentifier) setup() } - func setup() { + public func setup() { } - func configureView(data: MYHeaderFooterViewData) { + public func configureView(data: MYHeaderFooterViewData) { self.delegate = data } @@ -61,10 +61,10 @@ public class MYHeaderFooterView : UITableViewHeaderFooterView, MYBaseViewProtoco // MARK - Hightlight public extension MYHeaderFooterView { - public func highlight(animated: Bool) { + func highlight(animated: Bool) { } - public func unhighlight(animated: Bool) { + func unhighlight(animated: Bool) { } } diff --git a/Source/MYLabel.swift b/Source/MYLabel.swift index c040c27..b6541fa 100644 --- a/Source/MYLabel.swift +++ b/Source/MYLabel.swift @@ -8,8 +8,8 @@ import UIKit -class MYLabel : UILabel { - override var bounds: CGRect { +public class MYLabel : UILabel { + override public var bounds: CGRect { didSet { self.preferredMaxLayoutWidth = self.bounds.width } diff --git a/Source/MYTableViewCell.swift b/Source/MYTableViewCell.swift index 4166424..1361d94 100644 --- a/Source/MYTableViewCell.swift +++ b/Source/MYTableViewCell.swift @@ -19,7 +19,7 @@ public class MYTableViewCellData : MYBaseViewData { } } - init(cellClass: AnyClass, height: CGFloat = 44, userData: AnyObject?, selectionHandler: MYSelectionHandler? = nil) { + public init(cellClass: AnyClass, height: CGFloat = 44, userData: AnyObject?, selectionHandler: MYSelectionHandler? = nil) { self.identifier = String.className(cellClass) self.cellHeight = height super.init(userData: userData, selectionHandler: selectionHandler) @@ -32,7 +32,7 @@ public class MYTableViewCell : UITableViewCell, MYBaseViewProtocol { private weak var delegate: MYBaseViewDelegate? weak var cellData: MYTableViewCellData? - override init() { + public override init() { super.init() setup() } @@ -42,12 +42,12 @@ public class MYTableViewCell : UITableViewCell, MYBaseViewProtocol { setup() } - override init(frame: CGRect) { + public override init(frame: CGRect) { super.init(frame: frame) setup() } - override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + public override init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) setup() } diff --git a/Source/MYTableViewManager.swift b/Source/MYTableViewManager.swift index 1b20ba0..d50b02d 100644 --- a/Source/MYTableViewManager.swift +++ b/Source/MYTableViewManager.swift @@ -30,7 +30,7 @@ public enum MYReloadType { case None } -@objc protocol MYTableViewManagerDelegate : class { +@objc public protocol MYTableViewManagerDelegate : class { optional func scrollViewDidScroll(scrollView: UIScrollView) optional func scrollViewWillBeginDecelerating(scrollView: UIScrollView) optional func scrollViewWillBeginDragging(scrollView: UIScrollView) @@ -53,22 +53,7 @@ public class MYTableViewManager : NSObject { var loadmoreEnabled = false var loadmoreThreshold: CGFloat = 25 - subscript(index: Int) -> [MYTableViewCellData] { - get { - if dataSource.indexForKey(index) != nil { - return dataSource[index]! - } else { - numberOfSections = max(numberOfSections, index + 1) - dataSource[index] = [] - return dataSource[index]! - } - } - set(newValue) { - dataSource[index] = newValue - } - } - - init(tableView: UITableView) { + public init(tableView: UITableView) { super.init() self.tableView = tableView tableView.delegate = self