Skip to content

Instantly share code, notes, and snippets.

View yfujiki's full-sized avatar
💭
Moving around

Yuichi Fujiki yfujiki

💭
Moving around
  • Athlee Ltd
  • Japan
View GitHub Profile
@yfujiki
yfujiki / ViewModelTests.swift
Last active January 25, 2021 09:53
ViewModelTests for PhantomMockObject Project --- Fail
class ViewModelTests: XCTestCase {
var sut: ViewModel!
var logger: MockLoggerProtocol!
override func setUpWithError() throws {
}
override func tearDownWithError() throws {
}
@yfujiki
yfujiki / CacheLabel.swift
Last active February 28, 2020 19:43
Cache Label
private var labelCache = [IndexPath: UILabel]()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
...
if labelCache[indexPath] == nil {
let label = UILabel()
label.text = ...
labelCache[indexPath] = label
}
@yfujiki
yfujiki / CashbackLeaderboard.csv
Last active February 27, 2020 05:54
CashbackLeaderboard
Rank Nick Name Last Cashback Date Total Cashback Boosted Cashback
1 QueenOfCashback 23/02/2020 1024SGD 256SGD
2 Yu...LA6n4W 04/02/2020 666SGD 222SGD
3 ChaChaCha 03/02/2020 444SGD 111SGD
@yfujiki
yfujiki / UILabel-optimisation3.csv
Last active February 28, 2020 19:08
UILabel-optimisation3.csv
Base(MB) After(MB) Diff(MB)
Simple Label 6.34 6.59 0.25
Simple Label with Nilify 6.46 6.48 0.02
Cached Simple Label 6.57 11.71 5.14
Attributed Label 6.38 6.53 0.15
Attributed Label with Nilify 6.50 6.61 0.11
Cached Attributed Label 6.64 12.07 5.43
@yfujiki
yfujiki / UILabel-optimisation2.csv
Last active February 28, 2020 19:07
UILabel-optimisation2.csv
Base(MB) After(MB) Diff(MB)
Simple Label 6.34 6.59 0.25
Simple Label with Nilify 6.46 6.48 0.02
Attributed Label 6.38 6.53 0.15
Attributed Label with Nilify 6.50 6.61 0.11
@yfujiki
yfujiki / UILabel-optimisation1.csv
Last active February 28, 2020 19:07
UILabel-optimisation1.csv
Base(MB) After(MB) Diff(MB)
Simple Label 6.34 6.59 0.25
Simple Label with Nilify 6.46 6.48 0.02
Cached Simple Label 6.57 11.71 5.14
Attributed Label 6.38 6.53 0.15
Attributed Label with Nilify 6.50 6.61 0.11
Cached Attributed Label 6.64 12.07 5.43
Image 6.31 6.59 0.28
Image with Nilify 6.34 6.55 0.21
Cached Image 6.92 14.82 7.90
@yfujiki
yfujiki / ScratchCard-InspectImage.swift
Last active January 17, 2020 12:34
ScratchCard implementation inspect scratched area
extension UIView {
func transparentPercentage() -> Double {
let width = Int(bounds.width)
let height = Int(bounds.height)
// 1. Prepare a memory space where you write in RGBA data of the view
var pixelData: [UInt8] = Array<UInt8>(repeating: 0, count: width * height * 4)
let colorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)
override func draw(_ rect: CGRect) {
super.draw(rect)
}
override func draw(_ layer: CALayer, in context: CGContext) {
super.draw(layer, in: context)
// 1. Let the subviews to render into the context
foregroundView?.layer.render(in: context)
@yfujiki
yfujiki / ScratchCard-TouchHandling.swift
Last active January 17, 2020 12:35
SracthCard Touch Handling
private var previousLocation: CGPoint?
// 0. Line/LineCollection class is a convenience class to store line(s)
private var lineCollection: LineCollection = LineCollection()
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
// 1. If there is no touch point or if the point did not move, ignore
guard let touch = touches.first else {
return
}
let location = touch.location(in: self)
func setupCatsSection() -> NSCollectionLayoutSection {
// 1. Configuring Section. Item -> Group -> Section
// Item
let item = NSCollectionLayoutItem(
layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalHeight(1.0)))
item.contentInsets = NSDirectionalEdgeInsets(top: 6.7, leading: 10.0, bottom: 6.7, trailing: 10.0)
// Group
let group = NSCollectionLayoutGroup.vertical(