Skip to content

Instantly share code, notes, and snippets.

View vasilevkin's full-sized avatar
👷‍♂️
working

Sergey Vasilevkin vasilevkin

👷‍♂️
working
View GitHub Profile
override public func viewDidLoad() {
super.viewDidLoad()
print("Hello world")
}
@vasilevkin
vasilevkin / helloWorld.m
Created November 19, 2018 09:28
Simple example of Objective-C code
NSLog(@"Hello World!");
float aFloat = 1.2345;
NSLog(@"This is a float: %f", aFloat);
switch responseCode {
case -1:
text = "Unknown error"
break
case 0:
text = "Code is accepted"
break
}
@vasilevkin
vasilevkin / simpleAlert.swift
Last active November 20, 2018 06:35
Just a boiler plate code to display simple alert in Swift.
let alert = UIAlertController(title: "Simple Title",
message: "Alert message",
preferredStyle: .alert)
let okAction = UIAlertAction(title: "Close", style: .default)
alert.addAction(okAction)
DispatchQueue.main.async {
UIApplication.topViewController()?.present(alert, animated: true, completion: nil)
}
self.demoView.translatesAutoresizingMaskIntoConstraints = NO;
UILayoutGuide * guide = self.view.safeAreaLayoutGuide;
[self.demoView.leadingAnchor constraintEqualToAnchor:guide.leadingAnchor].active = YES;
[self.demoView.trailingAnchor constraintEqualToAnchor:guide.trailingAnchor].active = YES;
[self.demoView.topAnchor constraintEqualToAnchor:guide.topAnchor].active = YES;
[self.demoView.bottomAnchor constraintEqualToAnchor:guide.bottomAnchor].active = YES;
demoView.translatesAutoresizingMaskIntoConstraints = false
if #available(iOS 11.0, *) {
let guide = self.view.safeAreaLayoutGuide
demoView.trailingAnchor.constraint(equalTo: guide.trailingAnchor).isActive = true
demoView.leadingAnchor.constraint(equalTo: guide.leadingAnchor).isActive = true
demoView.bottomAnchor.constraint(equalTo: guide.bottomAnchor).isActive = true
demoView.topAnchor.constraint(equalTo: guide.topAnchor).isActive = true
} else {
NSLayoutConstraint(item: demoView, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1.0, constant: 0).isActive = true
NSLayoutConstraint(item: demoView, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier: 1.0, constant: 0).isActive = true
private static func value<T>(valueRaw: LoginResponse) -> T {
return valueRaw as! T
}
private static func value<T>(valueRaw: LoginResponse) -> T {
guard let castedValue = valueRaw as? T else {
fatalError("Unable to cast \(valueRaw) to \(T.self).")
}
return castedValue
}
private static func value<T>(valueRaw: LoginResponse) -> T? {
return valueRaw as? T
}
enum ErrorsWhenCasting : Error {
case wrongType
}
private static func value<T>(valueRaw: LoginResponse) throws -> T {
guard let castedValue = valueRaw as? T else {
throw ErrorsWhenCasting.wrongType
}
return castedValue
}