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
@SergLam
SergLam / CLPlacemark+Ext.swift
Last active March 28, 2019 19:02
MapKit full location address
import MapKit
import CoreLocation
import Foundation
extension MKMapItem {
var fullName: String {
guard let name = name, !placemark.fullLocationAddress.contains(name) else {
return placemark.fullLocationAddress
}
@SergLam
SergLam / Polyline.swift
Created March 27, 2019 18:08
Google Maps iOS Polyline with dashes
func drawPolyline() {
let path = GMSMutablePath()
path.add(CLLocationCoordinate2D(latitude: 50.014787, longitude: 36.232725))
path.add(CLLocationCoordinate2D(latitude: 50.014997, longitude: 36.233533))
path.add(CLLocationCoordinate2D(latitude: 50.016942, longitude: 36.232385))
path.add(CLLocationCoordinate2D(latitude: 50.016019, longitude: 36.226335))
path.add(CLLocationCoordinate2D(latitude: 50.010419, longitude: 36.227913))
let rectangle = GMSPolyline(path: path)
@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) {
@SergLam
SergLam / AppTypeDefinitions.swift
Last active March 18, 2024 09:09
Photo selection service class for iOS
typealias Localizable = R.string.localizable
typealias TypeClosure<T> = (T) -> Void
typealias VoidClosure = () -> Void
typealias VoidResult = Swift.Result<Void, Error>
typealias VoidResultClosure = (Swift.Result<Void, Error>) -> Void
typealias ImagePickerConfiguration = (source: UIImagePickerController.SourceType,
isLimited: Bool,
@SergLam
SergLam / PKHUD.swift
Created April 3, 2019 11:39
PKHUD Custom layout
fileprivate func showImageLoadingProgress() {
let imageSize = CGSize(width: UIScreen.width / 2, height: UIScreen.width / 2)
let imageLoadingProgressView = UIImageView(frame: CGRect(origin: CGPoint.zero, size: imageSize))
PKHUD.sharedHUD.contentView = imageLoadingProgressView
let fileName = R.image.imageLoaderGif.name.replacingOccurrences(of: ".gif", with: "")
imageLoadingProgressView.loadGif(name: fileName)
PKHUD.sharedHUD.show()
}
@SergLam
SergLam / MoyaNetworkService.swift
Last active September 21, 2019 18:04
Moya Network Logger Pretty JSON
import Foundation
import Moya
import Alamofire
// NOTE: Custom timeout configuration
class DefaultAlamofireManager: Alamofire.SessionManager {
static let sharedManager: DefaultAlamofireManager = {
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders
configuration.timeoutIntervalForRequest = 10
@SergLam
SergLam / UIBezierPath.swift
Created April 4, 2019 14:18
UIBezierPath border color
// Add border
let gradient = CAGradientLayer()
let size = CGSize(width: avatarSize, height: avatarSize)
let rect = CGRect(origin: .zero, size: size)
gradient.frame = CGRect(origin: CGPoint.zero, size: size)
gradient.colors = [UIColor.blue.cgColor, UIColor.green.cgColor]
let shape = CAShapeLayer()
shape.lineWidth = 5
shape.path = UIBezierPath(rect: rect).cgPath
@SergLam
SergLam / OnlyEnglish.swift
Created April 11, 2019 10:54
Validate only English regex
private func validateQuestionLanguage(_ question: String) -> Bool {
if question.isEmpty { return true }
do {
let regex = try NSRegularExpression(pattern: "^[a-zA-Z0-9\"$@$!%*?&#^-_. +()_\\-=\\[\\]{};:\\|,<>\\/?]+$", options: .caseInsensitive)
return regex.matches(in: question, options: [], range: NSRange(location: 0, length: question.count)).count > 0
} catch {
assert(false, "Invalid regex syntax")
}
}
@SergLam
SergLam / UIViewController+Ext.swift
Created April 12, 2019 13:23
Check if viewController isModal
func isModal() -> Bool {
let presentingIsModal = presentingViewController != nil
let presentingIsNavigation = navigationController?.presentingViewController?.presentedViewController == navigationController
let presentingIsTabBar = tabBarController?.presentingViewController is UITabBarController
return presentingIsModal || presentingIsNavigation || presentingIsTabBar
}
@SergLam
SergLam / UIImageView+Ext.swift
Created April 17, 2019 12:44
Round image view with gradient border color
import UIKit
extension UIImageView {
func addCircleGradiendBorder(_ width: CGFloat) {
let gradient = CAGradientLayer()
gradient.frame = CGRect(origin: CGPoint.zero, size: bounds.size)
let colors: [CGColor] = [UIColor.supSoftGreenThree.cgColor, UIColor.supSoftGreenTwo.cgColor,
UIColor.supSoftGreen.cgColor, UIColor.supTea.cgColor,
UIColor.supAquaMarineTwo.cgColor, UIColor.supAquaMarineThree.cgColor,