Quote from Silicon Valley Source: http://siliconvalleyism.com/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func loadPoseSamples() { | |
var poseSamples: [PoseSample] = [] | |
var text: String | |
do { | |
if let path = Bundle.main.path(forResource: Self.POSE_SAMPLES_FILE, ofType: Self.POSE_SAMPLES_FILE_EXT) { | |
text = try String(contentsOfFile: path, encoding: String.Encoding.utf8) | |
} else { | |
print(TAG, "Could not find file.") | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"message" : "Success", | |
"success" : true, | |
"data" : { | |
"profile" : { | |
"first_name" : "Christopher", | |
"middle_name" : "https://randomuser.me/api/portraits/men/78.jpg", | |
"last_name" : "Shelton", | |
"profile_image" : "", | |
"city" : "Krakow", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ReusableView.swift | |
// Ranjithkumar Matheswaran | |
// | |
// Created by Ranjithkumar Matheswaran on 31/10/18. | |
// Copyright © 2018 AgentDesks LLC. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Registering for UITableView | |
myTableView.register(MyCustomTableViewCell.self) | |
myTableView.register(MyCustomHeaderFooterView.self) | |
/// Registering for UICollectionView | |
myCollectionView.register(MyCustomCollectionViewCell.self) | |
myCollectionView.register(MyCollectionViewReusableView.self) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// UITableViewCell | |
class MyCustomTableViewCell: UITableViewCell, ReusableView, NibLoadableView { | |
} | |
// Or More suggested way | |
extension MyCustomTableViewCell: ReusableView, NibLoadableView { } | |
/// UITableViewHeaderFooterView | |
class MyCustomHeaderFooterView: UITableViewHeaderFooterView, ReusableView, NibLoadableView { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Dequeue methods for UICollectionView | |
func dequeueReusableCell<T: UICollectionViewCell>(for indexPath: IndexPath) -> T where T: ReusableView { | |
guard let cell = dequeueReusableCell(withReuseIdentifier: T.defaultReuseIdentifier, for: indexPath) as? T else { | |
fatalError("Could not dequeue cell with identifier: \(T.defaultReuseIdentifier)") | |
} | |
return cell | |
} | |
func dequeueReusableSupplementaryView<T: UICollectionReusableView>(ofKind: String, indexPath: IndexPath) -> T where T: ReusableView { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CollectionView | |
extension UICollectionView { | |
func register<T: UICollectionViewCell>(_: T.Type) where T: ReusableView { | |
register(T.self, forCellWithReuseIdentifier: T.defaultReuseIdentifier) | |
} | |
func register<T: UICollectionViewCell>(_: T.Type) where T: ReusableView, T: NibLoadableView { | |
let bundle = Bundle(for: T.self) | |
let nib = UINib(nibName: T.nibName, bundle: bundle) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension ReusableView where Self: UIView { | |
static var defaultReuseIdentifier: String { | |
return String(describing: self) | |
} | |
} | |
extension NibLoadableView where Self: UIView { | |
static var nibName: String { | |
return String(describing: self) | |
} |
NewerOlder