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
/// Sometimes we need to limit values | |
/// For instance, you are making application for the Tour De France, and | |
/// You have a variable depicting the Climb category (1..5) | |
/// Here is the place, where `Bounded` can be used | |
struct Bounded<T: Comparable> { | |
var minimum: T | |
var maximum: T | |
var value: T? { | |
willSet { |
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
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1 /*Delay time from now*/) { | |
// Your needed function | |
} |
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
[ | |
{ | |
"id": "af", | |
"description": "Afrikaans" | |
}, | |
{ | |
"id": "af-NA", | |
"description": "Afrikaans (Namibia)" | |
}, | |
{ |
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 math | |
def to_deg(angle): | |
return angle * (180 / math.pi) | |
def to_rad(angle): | |
return angle * (math.pi / 180) | |
# Environment | |
airDensity = 1.2234 # kg/m^3 |
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 <#ClassName#>: UIView { | |
// Do not forget to wire to XIB | |
@IBOutlet var view: UIView! | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
loadFromNib() | |
} | |
init() { |
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
extension CGSize { | |
enum AspectMode { | |
case fit | |
case fill | |
} | |
enum Orientation { | |
case portrait | |
case landscape | |
} |
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 Foundation | |
/* | |
> Closures are self-contained blocks of functionality that can be passed around and used in your code. Closures in Swift are similar to blocks in C and Objective-C and to lambdas in other programming languages. Swift’s closure expressions have a clean, clear style, with optimizations that encourage brief, clutter-free syntax in common scenarios. | |
For better understanding, I strongly recommend you to read the [Swift functions cheatsheet]({% post_url 2016-02-12-swift-functions-cheatsheet %}) and it's sources. | |
# Closure syntax | |
Since any function is the special case of closure, they are pretty the same. Basic difference is the way of writing and the use purpose. Closures syntax is optimized to be convenient for *inlining*, *passing as parameter* and *using as return type* of other functions. | |
The general form of the Swift closure is: | |
{ (parameters) -> ReturnType in |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
/*: | |
## `Date` wrapping and convenience methods | |
*/ | |
let calendar = Calendar.current | |
extension Int { | |
public var days: DateComponents { |
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
// | |
// Created by Oleksandr Glagoliev on 05/11/2018. | |
// Copyright © 2018 Oleksandr Glagoliev. All rights reserved. | |
// | |
import UIKit | |
class PlaceholderTextView: UITextView { | |
var placeholderColor: UIColor = .lightGray | |
var defaultTextColor: UIColor = .black |
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 Foundation | |
protocol CustomProtocol { | |
associatedtype AssociatedType | |
func foo(argument: AssociatedType) | |
} | |
//let array = [CustomProtocol]() // Gives error: Protocol 'CustomProtocol' can only be used as a generic constraint because it has Self or associated type requirements | |
public struct AnyCustomProtocol<T>: CustomProtocol { |
OlderNewer