Skip to content

Instantly share code, notes, and snippets.

@AlexandrFadeev
AlexandrFadeev / ProductDetails.swift
Created June 30, 2021 07:16
Product details in Bambinifasion project
import UIKit
let prevImageIconName = "prevImageIcon"
let nextImageIconName = "nextImageIcon"
let favoriteIconName = "favoriteIcon"
let productDetailsViewImageSliderWidthKoef: CGFloat = 0.96
protocol ProductDetailsViewDelegate: AnyObject {
@AlexandrFadeev
AlexandrFadeev / netstedContainer.swift
Created June 13, 2021 11:24
Decodable netsted containers
class Product: Decodable {
var id: Int
var art: String?
var title: String?
var votesCount: Int
var averageRating: Double
enum CodingKeys: String, CodingKey {
case id
@AlexandrFadeev
AlexandrFadeev / SwiftUIPreviewForUIKit.swift
Created January 19, 2021 08:19
SwiftUI live preview for UIKit apps
#if DEBUG
import SwiftUI
struct <#ViewController#>Presentable: UIViewControllerRepresentable {
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
}
@available(iOS 13.0, *)
func makeUIViewController(context: Context) -> UIViewController {
@AlexandrFadeev
AlexandrFadeev / UIImageExtension.swift
Last active October 16, 2023 23:41
UIImage asset identifier extenstion
extension UIImage {
enum AssetIdentifier: String {
case someImageName = "image-name-string"
}
convenience init!(assetIdentifier: AssetIdentifier) {
self.init(named: assetIdentifier.rawValue)
}
}
@AlexandrFadeev
AlexandrFadeev / DynamicColor.swift
Created February 21, 2020 10:59
Dynamic color in code
let dynamicColor = UIColor { (traitCollection: UITraitCollection) -> UIColor in
if traitCollection.userInterfaceStyle == .dark {
return .black
} else {
return .white
}
}
@AlexandrFadeev
AlexandrFadeev / semaphore.m
Created October 2, 2019 06:24
Semaphore example in Objective C
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[object runSomeLongOperationAndDo:^{
// hack hack hack...
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
dispatch_release(sema);
@AlexandrFadeev
AlexandrFadeev / layout.m
Last active June 27, 2019 13:55
CollectionView layout on device rotation
// Subclass UICollectionViewFlowLayout and overrite this method.
- (UICollectionViewLayoutInvalidationContext *)invalidationContextForBoundsChange:(CGRect)newBounds {
UICollectionViewFlowLayoutInvalidationContext *context = (UICollectionViewFlowLayoutInvalidationContext *)[super invalidationContextForBoundsChange:newBounds];
context.invalidateFlowLayoutDelegateMetrics = (
CGRectGetWidth(newBounds) != CGRectGetWidth(self.collectionView.bounds) ||
CGRectGetHeight(newBounds) != CGRectGetHeight(self.collectionView.bounds)
);
return context;
}
@AlexandrFadeev
AlexandrFadeev / reinstall iOS Simulators.txt
Created April 2, 2019 07:23
Reinstall Xcode iOS Simulators
1) Quit Xcode, Simulator, Instruments, etc.
2) Run in Terminal: sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService
3) Run in Terminal: sudo rm -rf ~/Library/*/CoreSimulator
# Was tested on Xcode 10.2 and iOS Simulator 12.2
@AlexandrFadeev
AlexandrFadeev / .gitconfig
Created December 26, 2018 10:10
Find parent branch
[alias]
parent = "!git show-branch | grep '*' | grep -v \"$(git rev-parse --abbrev-ref HEAD)\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//' #"
private func setupFormValidator() {
formValidator.rules.minValue = 1
formValidator.rules.maxValue = 2000
formValidator.addValidationTo(
view: receiverTextField, type: .require, fieldType: .none, errorMessage: "EmptyFormFieldError".localized,
errorMessageTitle: formTitleLabel.text)
if transferType == .receive || transferType == .refund {
formValidator.addValidationTo(