Skip to content

Instantly share code, notes, and snippets.

View NikKovIos's full-sized avatar
💭
Ready to work!) Zog zog

NikeKov NikKovIos

💭
Ready to work!) Zog zog
View GitHub Profile
@NikKovIos
NikKovIos / copy-xcode-prefs-script
Last active February 11, 2023 10:52
Xcode Save Preferences Ruby script. Save and cache key bindings, color theme, snippets and so on. Just copy to text file, correct text in <> and do the chmod 700.
#!/bin/bash
modelNumber=$(/usr/sbin/ioreg -l | awk '/product-name/ { split($0, line, "\""); printf("%s\n", line[4]); }')
now=`date +%d-%m-%Y_%H-%M`
destinationFolder="Xcode($now)-$modelNumber"
target="/Users/<yourUser>/Library/Developer/Xcode/UserData"
destination="<where to place>/$destinationFolder"
userDataFolderName="UserData"
libraryPreferencesTarget="/Users/<yourUser>/Library/Preferences"
@NikKovIos
NikKovIos / Collection+SetTransforming.swift
Created September 27, 2021 08:27
Converting Optional Array to Optional Set
extension Optional where Wrapped: Collection, Wrapped.Element: Hashable {
func transformToSet() -> Set<Wrapped.Element>? {
if let self = self {
return Set(self)
} else {
return nil
}
}
}
@NikKovIos
NikKovIos / CLLocationCoordinate2D+Equatable.swift
Created April 2, 2021 15:17
CLLocationCoordinate2D Equatable with accuracy
extension CLLocationCoordinate2D: Equatable {
public static func == (lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool {
let numbersAfterCommaAccuracy: Double = 4
let ratio = numbersAfterCommaAccuracy * 10
let isLatitudeEqual = ((lhs.latitude - rhs.latitude) * ratio).rounded(.down) == 0
let isLongitudeEqual = ((lhs.latitude - rhs.latitude) * ratio).rounded(.down) == 0
return isLatitudeEqual && isLongitudeEqual
}
}
@NikKovIos
NikKovIos / UIImage+Color.swift
Last active September 16, 2019 07:37
Extension to make an image from UIColor
extension UIImage {
class func image(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) -> UIImage {
return UIGraphicsImageRenderer(size: size).image { rendererContext in
color.setFill()
rendererContext.fill(CGRect(origin: .zero, size: size))
}
}
}
@NikKovIos
NikKovIos / UIButton+ActionBlock.swift
Last active October 1, 2020 18:16
Add the block closure to the UIButton.
/// Block for addTarget
extension UIControl {
public typealias UIControlActionBlock = (_ sender: UIControl) -> Void
public class UIControlClosureWrapper {
let owner: UIControl
let actionBlock: UIControlActionBlock
let event: UIControlEvents
//
// ClockView.h
//
#import <UIKit/UIKit.h>
@interface ClockView : UIControl {
NSTimer *updateTimer_;
CAShapeLayer *hourHand_;
@NikKovIos
NikKovIos / KeyboardTextField.m
Created April 2, 2018 17:25
Keyboard handling when it overlaps a TextField. Without scroll view.
@interface KeyboardTextField()
@end
@implementation KeyboardTextField
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil];
@NikKovIos
NikKovIos / NibInitializableView.swift
Last active March 23, 2018 23:00
Swift class to initialize UIView from xib
//
// NibInitializableView.swift
// nik-kov.com
//
// Created by Nik Kov on 16.11.17.
// Copyright © 2017 Nik Kov. All rights reserved.
//
/// Just subclass it
@IBDesignable
@NikKovIos
NikKovIos / NibInstantiableView.h
Last active April 30, 2020 20:40
Objective-C Class for loading view from xib
//
// NibInstantiableView.h
// nik-kov.com
//
// Created by Nik Kov on 23.03.2018.
// Copyright © 2018 Apple. All rights reserved.
//
#import <UIKit/UIKit.h>
@NikKovIos
NikKovIos / RealmIndexOutOfBoundsFix.swift
Last active February 10, 2018 08:23
Realm prevent crash for `Index x is out of bounds (must be less than x)`
// Use
if indexPath.row < arrayOfObjects.count {
cell.label.text = arrayOfObjects[indexPath.row]
} else {
// Handle non-existing object here
}
// Example:
if let wheel = wheel, let row = indexPath?.row, row < wheel.comments.count {
let comment = wheel.comments[row]