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
// | |
// ContentView.swift | |
// CollectionView | |
// | |
// Created by Chris Eidhof on 20.08.19. | |
// Copyright © 2019 Chris Eidhof. All rights reserved. | |
// | |
import SwiftUI |
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
final class MyCell: UICollectionViewCell { | |
override var isHighlighted: Bool { | |
didSet { | |
shrink(down: isHighlighted) | |
} | |
} | |
} |
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
// You can make it nicer by using enum (.down, .up) instead of Bool | |
func shrink(down: Bool) { | |
UIView.animate(withDuration: 0.6) { | |
if down { | |
cell.transform = CGAffineTransform(scaleX: 0.8, y: 0.8) | |
else { | |
cell.transform = .identity | |
} | |
} | |
} |
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 EarlGrey | |
import Salsa | |
import XCTest | |
@testable import YourApp | |
class Test: XCTestCase { | |
override func setup() { | |
super.setup() | |
} |
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
{ | |
"applmusic": { | |
"code": "AAPL", | |
"quality": "good", | |
"line": "She told me don't worry" | |
}, | |
"spotify": { | |
"differentcode": "SPOT", | |
"music_quality": "good", | |
"spotify_specific_code": "absent in apple" |
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
{ | |
"applmusic":{ | |
"code":"AAPL", | |
"quality":"good", | |
"line":"She told me don't worry", | |
}, | |
"spotify":{ | |
"differentcode":"SPOT", | |
"music_quality":"good", | |
"spotify_specific_code":"absent in apple" |
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
// Linear cell's size animation | |
UIView.animate(withDuration: self.transitionDuration(using: ctx), animations: { | |
// other animations ... | |
// card width & height expansion (widthAnc and heightAnc are stored previously) | |
self.widthAnc.constant = detailVc.cardContentView.bounds.width | |
self.heightAnc.constant = detailVc.cardContentView.bounds.height | |
// call layoutIfNeeded() on the animatingContainerOView | |
self.animatingContainerView.layoutIfNeeded() |
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 SomeTransitionManager: UIPercentDrivenInteractiveTransition, UIViewControllerAnimatedTransitioning { | |
// .. | |
} | |
// Bind everything together | |
extension SomeTransitionManager: UIViewControllerTransitioningDelegate { | |
func animationController(fortPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { | |
return self | |
} | |
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { |
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 SomeViewController: UIViewController { | |
private let serviceBuilder: () -> Service | |
private lazy var service: Service = serviceBuilder() // build when it’s really needed. | |
// Lazy dependency injection! | |
init(service: @escaping @autoclosure () -> Service) { | |
serviceBuilder = service | |
} | |
func fetch() { |
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
func fetchObject(id: Int, @escaping completion: (Object) -> Void) { | |
let request = ... | |
APIService.get(request) { result in | |
switch result { | |
case .success(let object): | |
completion(object) | |
case .error: | |
// make default object, not so flexible here... | |
let defaultObject = makeDefaultObject() | |
completion(defaultObject) |
NewerOlder