Skip to content

Commit

Permalink
Project moved to Swift 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
robertherdzik committed Nov 13, 2016
1 parent de41025 commit b153e78
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = x.RHPreviewCellExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -349,7 +349,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = x.RHPreviewCellExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

let windowFrame = UIScreen.mainScreen().bounds
let windowFrame = UIScreen.main.bounds
window = UIWindow(frame: windowFrame)

let mainVC = ViewController(withMock: RHMockCellsModel())
Expand All @@ -19,4 +19,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

return true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit

class DetailsViewController: UIViewController {

private let image: UIImage
fileprivate let image: UIImage

init(withImage image: UIImage) {
self.image = image
Expand All @@ -22,7 +22,7 @@ class DetailsViewController: UIViewController {
return view as! DetailsView
}

override func viewDidAppear(animated: Bool) {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

showImage()
Expand All @@ -32,20 +32,20 @@ class DetailsViewController: UIViewController {
castView().imageView.alpha = 0
castView().setImage(image)

UIView.animateWithDuration(0.2) { [weak self] in
UIView.animate(withDuration: 0.2, animations: { [weak self] in
self?.castView().imageView.alpha = 1
}
})
}
}

class DetailsView: UIView {

private let imageView = UIImageView()
fileprivate let imageView = UIImageView()

init() {
super.init(frame: CGRectZero)
super.init(frame: CGRect.zero)

backgroundColor = UIColor.whiteColor()
backgroundColor = UIColor.white
addSubview(imageView)
}

Expand All @@ -57,11 +57,11 @@ class DetailsView: UIView {
super.layoutSubviews()

let edgeSize = CGFloat(300)
imageView.frame = CGRectMake(0, 0, edgeSize, edgeSize)
imageView.frame = CGRect(x: 0, y: 0, width: edgeSize, height: edgeSize)
imageView.center = center
}

func setImage(image: UIImage) {
func setImage(_ image: UIImage) {
imageView.image = image
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class MainControllerView: UIView {
tableView.frame = bounds
}

func set(tableView tableView: UITableView) {
func set(tableView: UITableView) {
self.tableView = tableView

addSubview(self.tableView)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ class NextViewController: UIViewController {
return view as! NextView
}

override func viewDidAppear(animated: Bool) {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

}
}

class NextView: UIView {

let loadSpinner = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
let loadSpinner = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)

init() {
super.init(frame: CGRectZero)
super.init(frame: CGRect.zero)

backgroundColor = UIColor.whiteColor()
backgroundColor = UIColor.white

addSubview(loadSpinner)
loadSpinner.startAnimating()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import RHPreviewCell

class ViewController: UIViewController {

private let reuseCellIdentifier = "RHPreviewCell_id"
private let mockModel: RHMockCellsModel
fileprivate let reuseCellIdentifier = "RHPreviewCell_id"
fileprivate let mockModel: RHMockCellsModel

init(withMock mock: RHMockCellsModel) {
mockModel = mock
Expand All @@ -26,62 +26,62 @@ class ViewController: UIViewController {
view = MainControllerView()
}

private func castView() -> MainControllerView {
fileprivate func castView() -> MainControllerView {
return view as! MainControllerView
}

func setupTableView() {
let tableView = UITableView(frame: CGRectZero, style: .Grouped)
tableView.registerClass(UITableViewCell.classForCoder(), forCellReuseIdentifier: "cell")
let tableView = UITableView(frame: CGRect.zero, style: .grouped)
tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: "cell")
tableView.delegate = self
tableView.dataSource = self

tableView.registerClass(RHPreviewTableViewCell.classForCoder(), forCellReuseIdentifier: reuseCellIdentifier)
tableView.register(RHPreviewTableViewCell.classForCoder(), forCellReuseIdentifier: reuseCellIdentifier)

castView().set(tableView: tableView)
}

private func pushNextViewController() {
fileprivate func pushNextViewController() {
let nextVC = NextViewController()
navigationController?.pushViewController(nextVC, animated: true)
}

private func presentDetailsViewController(withImage image: UIImage) {
fileprivate func presentDetailsViewController(withImage image: UIImage) {
let detailsVC = DetailsViewController(withImage: image)
let dismissButton = UIBarButtonItem(barButtonSystemItem: .Done, target: self, action: #selector(dismiss))
let dismissButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(dismissDetailController))
let navController = UINavigationController(rootViewController: detailsVC)
detailsVC.navigationItem.rightBarButtonItem = dismissButton

presentViewController(navController, animated: true, completion: nil)
present(navController, animated: true, completion: nil)
}

@objc private func dismiss() {
dismissViewControllerAnimated(true, completion: nil)
@objc fileprivate func dismissDetailController() {
self.dismiss(animated: true, completion: nil)
}
}

extension ViewController: UITableViewDelegate {

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)

pushNextViewController()
}
}

extension ViewController: UITableViewDataSource {

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return mockModel.cells.count
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return CGFloat(65)
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(reuseCellIdentifier) as! RHPreviewTableViewCell
cell.accessoryType = .DisclosureIndicator
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: reuseCellIdentifier) as! RHPreviewTableViewCell
cell.accessoryType = .disclosureIndicator
cell.delegate = self
cell.dataSource = self
cell.textLabel?.text = mockModel.cells[indexPath.row].title
Expand All @@ -93,38 +93,38 @@ extension ViewController: UITableViewDataSource {

extension ViewController: RHPreviewCellDelegate {

func previewCell(cell: RHPreviewTableViewCell, didSelectTileAtIndex indexValue: RHTappedTileIndexValue) {
let cellIndex = castView().tableView.indexPathForCell(cell)!.row
func previewCell(_ cell: RHPreviewTableViewCell, didSelectTileAtIndex indexValue: RHTappedTileIndexValue) {
let cellIndex = castView().tableView.indexPath(for: cell)!.row

switch indexValue {
case .TileTapped(let index):
case .tileTapped(let index):
print("😲 \(index) has been selected")

let tiles = mockModel.cells[cellIndex].tiles
let tileItem = tiles[index]

presentDetailsViewController(withImage: tileItem.image)
case .FingerReleased:
case .fingerReleased:
print("🖖🏽 Finger has been relesed")
}
}
}

extension ViewController: RHPreviewCellDataSource {

func previewCellNumberOfTiles(cell: RHPreviewTableViewCell) -> Int {
let cellIndex = castView().tableView.indexPathForCell(cell)!.row
func previewCellNumberOfTiles(_ cell: RHPreviewTableViewCell) -> Int {
let cellIndex = castView().tableView.indexPath(for: cell)!.row
let tiles = mockModel.cells[cellIndex].tiles

return tiles.count
}

func previewCell(cell: RHPreviewTableViewCell, tileForIndex: Int) -> RHPreviewTileView {
let cellIndex = castView().tableView.indexPathForCell(cell)!.row
func previewCell(_ cell: RHPreviewTableViewCell, tileForIndex: Int) -> RHPreviewTileView {
let cellIndex = castView().tableView.indexPath(for: cell)!.row
let tiles = mockModel.cells[cellIndex].tiles
let tileItem = tiles[tileForIndex]

let tile = RHPreviewTileView(frame: CGRectZero)
let tile = RHPreviewTileView(frame: CGRect.zero)
tile.image = tileItem.image

return tile
Expand Down
4 changes: 2 additions & 2 deletions Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ pod 'RHPreviewCell'
or you can simply copy ```RHPreviewCellSource``` folder to your project.

## Usage
To fully integrate RHPreviewCell with your Table View you just need to use RHPreviewCell like normal UITableViewCell in terms of your TableView data source 'cellForRowAtIndexPath' method.
To fully integrate RHPreviewCell with your Table View you just need to use RHPreviewCell like normal UITableViewCell in terms of your TableView data source 'cellForRowAtIndexPath' method.

```swift
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// Fetching already registered RHPreviewTableViewCell
let cell = tableView.dequeueReusableCellWithIdentifier(reuseCellIdentifier) as! RHPreviewTableViewCell
// Fetching already registered RHPreviewTableViewCell
let cell = tableView.dequeueReusableCellWithIdentifier(reuseCellIdentifier) as! RHPreviewTableViewCell

// Delegate using which, tiles will talk to your class
cell.delegate = self
cell.delegate = self
// Data source for feed small tiles 🚼
cell.dataSource = self

Expand All @@ -49,7 +49,7 @@ func previewCell(cell: RHPreviewTableViewCell, tileForIndex: Int) -> RHPreviewTi
```swift
func previewCell(cell: RHPreviewTableViewCell, didSelectTileAtIndex indexValue: RHTappedTileIndexValue)
```
And thats it! 💥 You have already integrete Library with your Table View 🎉
And thats it! 💥 You have already integrete Library with your Table View 🎉

<p align="center">
<img src ="./ReadmeAssets/second_video.gif" width="360" height="640" align="center"/>
Expand All @@ -75,13 +75,14 @@ func previewCell(cell: RHPreviewTableViewCell, didSelectTileAtIndex indexValue:
... as you can see delegate method as a argument takes ``` RHTappedTileIndexValue``` , yup... it is swift enum using which you will gather information about tapped tile (```.TileTapped(let index)``` ) or even whether user released his finger out of tiles area (```.FingerReleased``` ).

## Swift support
| Library ver| Swift ver|
| ------------- |:-------------:|
| Library ver| Swift ver|
| ------------- |:-------------:|
| 1.0.1 | 2.2 |
| 1.0.2 | 2.3 |
| 1.0.3 | 3.0 |



## Check the Demo project
## Check the Demo project

Please check out the demo project, you can see there how Library has been implemented in details.
Loading

0 comments on commit b153e78

Please sign in to comment.