Skip to content

Instantly share code, notes, and snippets.

View vialyx's full-sized avatar
🎯
Focusing

Maxim Vialyx vialyx

🎯
Focusing
View GitHub Profile
import Foundation
// TODO: - Move to the separated file Resource.swift
struct Resource {
let url: URL
let method: String = "GET"
}
// TODO: - Move to the separated file GenericResult.swift
enum Result<T> {
........
} else {
// Check animations in label layer
guard label.layer.animationKeys()?.isEmpty ?? true else {
// Clear existed animations
label.layer.removeAllAnimations()
// Backup center position
label.center = CGPoint(x: view.center.x, y: label.center.y)
return
}
@IBAction func buttonDidTap(_ sender: Any) {
// Check text in field. Animation is starting only if text is empty
if field.text?.isEmpty ?? true {
UIView.animate(withDuration: 0.3,
delay: 0.0,
// Look options list here https://developer.apple.com/documentation/uikit/uiviewanimationoptions
options: [.autoreverse],
animations: {
// Create CGAffineTransform with 5 degree (CG works with radians) and convert in to radians
self.field.transform = CGAffineTransform(rotationAngle: CGFloat(5).degreesToRadians)
// MARK: - Actions
@IBAction func buttonDidTap(_ sender: Any) {
// Check text in field. Animation is starting only if text is empty
if field.text?.isEmpty ?? true {
UIView.animate(withDuration: 0.3,
delay: 0.0,
// Look options list here https://developer.apple.com/documentation/uikit/uiviewanimationoptions
options: [.autoreverse],
animations: {
// Create CGAffineTransform with 5 degree (CG works with radians) and convert in to radians
import UIKit
final class ViewController: UIViewController {
@IBOutlet weak var field: UITextField!
@IBOutlet weak var label: UILabel!
@IBOutlet weak var button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
import UIKit
final class ViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
// Create constant data source
private let dataSource = DataSource()
override func viewDidLoad() {
super.viewDidLoad()
class ViewController: UIViewController {
@IBOutlet weak var table: UITableView!
// Create constant data source
private let dataSource = TableDataSource()
override func viewDidLoad() {
super.viewDidLoad()
// Attach to table view
dataSource.attach(to: table)
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var contentView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
contentView.backgroundColor = .yellow
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var contentView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Write that code
contentView.backgroundColor = .yellow
infix operator +++: AdditionPrecedence
extension Engine {
static func +++ (left: Engine, right: Engine) -> Engine {
let tank = max(left.tank, right.tank)
let consumption = min(left.consumption, right.consumption)
return Engine(tank: tank,
consumption: consumption,
distance: tank / consumption * 100,