Skip to content

Instantly share code, notes, and snippets.

View TsRebornz's full-sized avatar

Anton Makarenkov TsRebornz

  • Yerevan
View GitHub Profile
struct Car {
let gears: [Gear]
}
struct Gear {
let name: String
}
let firstGearKeyPath = \Car.gears[0].name
struct Size {
var width: Int // Changed to var
let height: Int
}
struct Table {
var size: Size // Changed to var
let material: String
}
let tableSizeKeyPath = \Table.size.width // KeyPath<Table, Int>
let tableMaterialKeyPath = \Table.material // KeyPath<Table, String>
let table = Table(
size: .init(width: 100, height: 20),
material: "wood"
)
print(table[keyPath: tableSizeKeyPath]) // 100
@TsRebornz
TsRebornz / Keypath_partialKeyPath.swift
Last active December 8, 2022 23:54
Keypath_partialKeyPath
struct Size {
let width: Int
let height: Int
}
struct Table {
let size: Size
let material: String
}
struct Size {
let width: Int
let height: Int
}
struct Table {
let size: Size
let material: String
}
@TsRebornz
TsRebornz / Keypath_mapping.swift
Last active August 31, 2022 16:35
Keypath_mapping
let phones: [Phone] = [
.init(model: "Samsung A3", manufacturer: "Samsung"),
.init(model: "iPhone 13", manufacturer: "Apple")
]
let phoneModels = phones.map(\.model)
let basicAnimation = CABasicAnimation(keyPath: "bounds")
@TsRebornz
TsRebornz / CircularProgressBarViewController.swift
Last active September 1, 2020 19:31
CircularProgressBarViewController
//
// CircularProgressBarViewController.swift
// iOS_CoreAnimation_Advanced_practice
//
// Created by Anton Makarenkov on 08/08/2020.
// Copyright © 2020 Anton Makarenkov. All rights reserved.
//
import UIKit
final class SharedTokenManager {
private let tokenKey = "token"
private let accessGroup: String
init(accessGroup: String) {
self.accessGroup = accessGroup
}
func getToken() -> String? {
@TsRebornz
TsRebornz / BackgroundTaskExample.m
Last active July 10, 2019 13:14
BackGroundTaskExample
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
NSLog(@"%s", __FUNCTION__);
__block UIBackgroundTaskIdentifier task = [application beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"Expiration handler called %f",[application backgroundTimeRemaining]);