Skip to content

Instantly share code, notes, and snippets.

View SergLam's full-sized avatar
😊
Try to make your code better!

Serhii Liamtsev SergLam

😊
Try to make your code better!
View GitHub Profile
@V8tr
V8tr / AutoLayoutDSL.swift
Last active October 22, 2024 17:20
Auto Layout DSL
import UIKit
/// Represents a single `NSLayoutConstraint`
enum LayoutAnchor {
case constant(attribute: NSLayoutConstraint.Attribute,
relation: NSLayoutConstraint.Relation,
constant: CGFloat)
case relative(attribute: NSLayoutConstraint.Attribute,
relation: NSLayoutConstraint.Relation,
@SergLam
SergLam / CustomVC.swift
Created January 7, 2021 20:16
SwiftUI previews for UIKit
import UIKit
final class CustomVC: UIViewController {
private lazy var contentView: CustomView = CustomView()
// MARK: - Life cycle
deinit {
NotificationCenter.default.removeObserver(self)
}
@SergLam
SergLam / ScrollView.m
Last active February 6, 2023 14:32
Scroll view constraints - programmaticaly + storyboard hack
// SnapKit(Masonry) 1
// https://github.com/SnapKit/Masonry
[self. addSubview: scrollView];
[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(safeAreaLayoutGuide);
}];
[scrollView addSubview: contentView];
[contentView mas_makeConstraints:^(MASConstraintMaker *make) {
@CanTheAlmighty
CanTheAlmighty / AsynchronousBlockOperation.swift
Last active April 13, 2020 07:47 — forked from Sorix/AsynchronousOperation.swift
Subclass of (NS)Operation to make it asynchronous in Swift 4, also providing a Block-based alternative.
//
// AsynchronousBlockOperation.swift
//
// Created by Jose Canepa on 12/13/17.
// Copyright © 2017 Jose Canepa. All rights reserved.
//
import Foundation
/// Block based version of the AsynchronousOperation
@yoni-g
yoni-g / closeAppElegantly.swift
Last active May 12, 2024 17:57
How to exit an iOS app without it looking like a crash? - Swift
func showMessageResetApp(){
let exitAppAlert = UIAlertController(title: "Restart is needed",
message: "We need to restart the app on your first login to the app.\n Please reopen the app after this.",
preferredStyle: .alert)
let resetApp = UIAlertAction(title: "Close Now", style: .destructive) {
(alert) -> Void in
// home button pressed programmatically - to thorw app to background
UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
// terminaing app in background
@ispiropoulos
ispiropoulos / UserDefaults+CLLocation.swift
Last active July 17, 2021 00:29
Store CLLocation into UserDefaults
//
// UserDefaults+CLLocation.swift
//
//
// Created by John Spiropoulos on 28/09/16.
// Copyright © 2016 John Spiropoulos. All rights reserved.
//
/*
Swift 3 Helper extension: