Skip to content

Instantly share code, notes, and snippets.

View superhard's full-sized avatar
🎯
Focusing

Artem superhard

🎯
Focusing
View GitHub Profile
@arturlector
arturlector / designated_initializer.md
Last active March 14, 2018 09:00
Что такое назначенный инициализатор (designated initializer)?

Что такое назначенный инициализатор?

Назначенный инициализатор (designated initializer) - это главный инициализатор(конструктор), все остальные методы
создающие класс вызывают этот метод.

Как выглядит назначенный инициализатор?

@IanKeen
IanKeen / NSTimeInterval+Extension.swift
Last active October 16, 2019 04:32
Working Swiftly with NSTimeInterval
enum TimePeriod {
case Seconds(Int)
case Minutes(Int)
case Hours(Int)
var timeInterval: NSTimeInterval {
switch self {
case .Seconds(let value): return NSTimeInterval(value)
case .Minutes(let value): return NSTimeInterval(value * 60)
case .Hours(let value): return NSTimeInterval(value * 60 * 60)
public extension Int {
public var seconds: DispatchTimeInterval {
return DispatchTimeInterval.seconds(self)
}
public var second: DispatchTimeInterval {
return seconds
}
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
/// define an operation success or error result
enum Result<T> {
case error(Error)
case success(T)
}

FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.


Effective Engineer - Notes

What's an Effective Engineer?

import UIKit
extension UITableView {
func registerNib<T: UITableViewCell>(forCellType type: T.Type) {
let name = String(describing: type)
let nib = UINib(nibName: name, bundle: nil)
register(nib, forCellReuseIdentifier: name)
}
func registerNib<T: UIView>(forHeaderFooterType type: T.Type) {
import Foundation
import UIKit
// Usage Examples
let shadowColor = Color.shadow.value
let shadowColorWithAlpha = Color.shadow.withAlpha(0.5)
let customColorWithAlpha = Color.custom(hexString: "#123edd", alpha: 0.25).value
enum Color {
@sauvikatinnofied
sauvikatinnofied / MediumBlogFontHandling_FullCode.swift
Last active October 25, 2023 14:57
MediumBlogFontHandling_FullCode
import Foundation
import UIKit
// Usage Examples
let system12 = Font(.system, size: .standard(.h5)).instance
let robotoThin20 = Font(.installed(.RobotoThin), size: .standard(.h1)).instance
let robotoBlack14 = Font(.installed(.RobotoBlack), size: .standard(.h4)).instance
let helveticaLight13 = Font(.custom("Helvetica-Light"), size: .custom(13.0)).instance
struct Font {
@kunikullaya
kunikullaya / Date+Extension.swift
Created January 18, 2017 05:21
Date Extension for Swift
import Foundation
extension Date {
func toString(format: String = "yyyy-MM-dd") -> String {
let formatter = DateFormatter()
formatter.dateStyle = .short
formatter.dateFormat = format
return formatter.string(from: self)
}
@karnlund
karnlund / UIViewFromNib.swift
Last active June 1, 2018 16:20
This is fromNib methods converted for Swift 3. This is obtained from StackOverflow here http://stackoverflow.com/questions/24857986/load-a-uiview-from-nib-in-swift
// This came from StackOverflow
// http://stackoverflow.com/questions/24857986/load-a-uiview-from-nib-in-swift
//
// https://gist.github.com/karnlund/b666acc88532d5f1ca591dd3580605cc
import UIKit
public extension UIView {
public class func fromNib(_ nibName: String? = nil) -> Self? {
return loadFromNib(nibName)