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
import UIKit | |
struct Person: ExpressibleByStringLiteral { | |
typealias StringLiteralType = String | |
init(stringLiteral value: StringLiteralType) { | |
let components = value.components(separatedBy: .whitespaces) | |
firstName = components[0] | |
lastName = components[1] | |
} | |
let firstName: String |
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
// A protocol to be used in our atomic type | |
protocol Operatable { | |
func add(other: Self) -> Self | |
} | |
// We will only limit our atomic type to Int, but it can be extended to use any other type | |
extension Int: Operatable { | |
func add(other: Int) -> Int { | |
return self + other | |
} |
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 updateLabelPosition(_ cell: TableViewCell) { | |
let point = view.convert(cell.contributerNameLabel.frame.origin, from: cell.contentView) // 1 | |
let ratio = point.y / viewHeight // 2 | |
let updatedConstraint = (ratio * constraintRange) + minimumConstraint // 3 | |
cell.nameLabelTopConstraint.constant = updatedConstraint // 4 | |
} |
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 ViewController: UITableViewDelegate { | |
// other implementaion | |
func scrollViewDidScroll(_ scrollView: UIScrollView) { | |
updateVisibleLabelPositions() | |
} | |
private func updateVisibleLabelPositions() { | |
guard let cells = tableView.visibleCells as? [TableViewCell] else { return } | |
for cell in cells { | |
updateLabelPosition(cell) | |
} |
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
class GridView: UIView { | |
// Only override draw() if you perform custom drawing. | |
// An empty implementation adversely affects performance during animation. | |
override func draw(_ rect: CGRect) { | |
// Drawing code | |
let borderLayer = gridLayer() | |
borderLayer.path = UIBezierPath(rect: bounds).cgPath |
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 UIImageView { | |
static var dataTask: URLSessionDataTask? | |
func download(urlString: String) { | |
guard let url = URL(string: urlString) else { | |
print("\(urlString) is not a valid url") | |
return | |
} | |
if let existingTask = UIImageView.dataTask { | |
if existingTask.state == .running { | |
existingTask.cancel() |
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
import android.view.animation.AccelerateInterpolator; | |
import android.view.animation.Interpolator; | |
import android.widget.TextView; | |
public class CountingHelper implements Runnable { | |
private final long mDuration; | |
private final int mStartingValue; | |
private final int mFinalValue; |