Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
@main
struct testSwitUIApp: App {
let persistenceController = PersistenceController.shared
@Environment (\.scenePhase) private var scenePhase
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@AlexZverusha
AlexZverusha / gist:dd1ec8881abc8c16580a8fd83643225c
Last active October 11, 2022 23:02
Protocol extensions magic in Swift
protocol SampleProtocol {
func foo()
}
extension SampleProtocol {
func foo() {
print("Protocol foo")
}
func bar() {
print("Protocol bar")
@AlexZverusha
AlexZverusha / CoreData + Codable.swift
Created November 6, 2020 14:58 — forked from Akhu/CoreData + Codable.swift
Mixing Codable and Core Data in Swift
//
// Article.swift
// Veille
//
// Created by Anthony Da Cruz on 26/01/2018.
// Copyright © 2018 Anthony Da Cruz. All rights reserved.
//
import Foundation
import CoreData
@AlexZverusha
AlexZverusha / gist:ff1129e1072197c1d9a82d23ffa39354
Created October 7, 2020 11:03
Rounding with NSDecimalNumberBehaviors
// sample
//let amountNumberBehaviors = AmountNumberBehaviors()
//let result = amountNumberBehaviors.round(value: value, style: .decades)
class AmountNumberBehaviors: NSDecimalNumberBehaviors {
var badException = false
func roundingMode() -> NSDecimalNumber.RoundingMode {
return .up
import CoreData
import Foundation
class CoreDataManager {
// Singleton
static let instance = CoreDataManager()
private init() {}
@AlexZverusha
AlexZverusha / gist:2b753fda868d1771c79093737171b76c
Created October 24, 2017 10:43
UILabel with text of two different colors
extension NSMutableAttributedString{
func setColorForText(_ textToFind: String, with color: UIColor) {
let range = self.mutableString.range(of: textToFind, options: .caseInsensitive)
if range.location != NSNotFound {
addAttribute(NSForegroundColorAttributeName, value: color, range: range)
}
}
}
Usage!

Вопросы на собеседование iOS разработчика (дополненное издание):

Полиморфизм — возможность объектов с одинаковой спецификацией иметь различную реализацию. Пример: Класс или интерфейс геометрических фигур (эллипс, многоугольник) может иметь методы для геометрических трансформаций (вычисление площади, смещение, поворот, масштабирование).

// 1
let replicatorLayer = CAReplicatorLayer()
replicatorLayer.frame = someView.bounds
// 2
replicatorLayer.instanceCount = 30
replicatorLayer.instanceDelay = CFTimeInterval(1 / 30.0)
replicatorLayer.preservesDepth = false
replicatorLayer.instanceColor = UIColor.whiteColor().CGColor
override func viewDidLoad() {
super.viewDidLoad()
// 1
let playerLayer = AVPlayerLayer()
playerLayer.frame = someView.bounds
// 2
let url = NSBundle.mainBundle().URLForResource("someVideo", withExtension: "m4v")
let player = AVPlayer(URL: url)
@AlexZverusha
AlexZverusha / Animation.md
Created September 1, 2017 13:22 — forked from JeOam/Animation.md
iOS Core Animation: Advanced Techniques, Part 1: The Layer Beneath

1. The Layer Tree

Core Animation's original name is Layer Kit

Core Animation is a compositing engine; its job is to compose different pieces of visual content on the screen, and to do so as fast as possible. The content in question is divided into individual layers stored in a hierarchy known as the layer tree. This tree forms the underpinning for all of UIKit, and for everything that you see on the screen in an iOS application.

In UIView, tasks such as rendering, layout and animation are all managed by a Core Animation class called CALayer. The only major feature of UIView that isn’t handled by CALayer is user interaction.

There are four hierarchies, each performing a different role:

  • view hierarchy
  • layer tree