Skip to content

Instantly share code, notes, and snippets.

View sukov's full-sized avatar

Gorjan Shukov sukov

View GitHub Profile
@sukov
sukov / UserDefaultsExtension.swift
Created December 23, 2021 15:39
Codable additions to UserDefaults
extension UserDefaults {
/// Sets the codable value of the specified key.
func set<Element: Codable>(_ value: Element, forKey key: String) {
let data = try? JSONEncoder().encode(value)
UserDefaults.standard.setValue(data, forKey: key)
}
/// Returns the codable value associated with the specified key.
func codable<Element: Codable>(forKey key: String) -> Element? {
guard let data = UserDefaults.standard.data(forKey: key) else { return nil }
@sukov
sukov / podforceupdate.sh
Last active February 5, 2022 14:04
Clear CocoaPods cache, re-download and re-install all pods
#!/usr/bin/env bash
rm -rf "${HOME}/Library/Caches/CocoaPods"
rm -rf "`pwd`/Pods/"
pod update
# In case a corrupt repo compromises `pod repo update` command
rm -rf ~/.cocoapods/repos
@sukov
sukov / CodableExtension.swift
Last active September 19, 2024 11:27 — forked from mikebuss/decode-json-swift.swift
Codable (Encode & Decode) [Any] and [String: Any] Swift 5
// Original: https://gist.github.com/loudmouth/332e8d89d8de2c1eaf81875cfcd22e24
import Foundation
private struct JSONCodingKeys: CodingKey {
var stringValue: String
init(stringValue: String) {
self.stringValue = stringValue
}
@sukov
sukov / appstoreconnect_navigation_toggle.js
Created July 5, 2019 20:20
App Store Connect / iTunes Connect wider App Screen by hiding navigation. Suggested use with JavaScript injection extension for your browser.
function toggleNavigation() {
var topPane = document.getElementById("appPageHeader");
var leftPane = document.getElementsByClassName("pane-layout-sidebar")[0];
var bottomPane = document.getElementsByClassName("pane-layout-content-header")[0];
var bottomPaneHeader = bottomPane.getElementsByClassName("pane-layout-content-header-text")[0];
var displayType = (topPane.style.display === "none") ? "block" : "none";
topPane.style.display = displayType;
leftPane.style.display = displayType;
//NOTE: Uncomment this line if you want to hide `Save` and `Submit` buttons, and remove the next two lines
@sukov
sukov / CaseIterable.swift
Created July 2, 2019 22:06
CaseIterable for older swift versions
#if !swift(>=4.2)
public protocol CaseIterable {
associatedtype AllCases: Collection where AllCases.Element == Self
static var allCases: AllCases { get }
}
extension CaseIterable where Self: Hashable {
static var allCases: [Self] {
return [Self](AnySequence { () -> AnyIterator<Self> in
var raw = 0
@sukov
sukov / UIButtonExtension.swift
Last active June 22, 2021 15:10
UIButton loading indicator
extension UIButton {
/// Unique number used to tag the loading indicator view
private var loadingIndicatorTag: Int {
808404
}
private var loadingIndicator: UIActivityIndicatorView? {
viewWithTag(loadingIndicatorTag) as? UIActivityIndicatorView
}
@sukov
sukov / UITableViewExtension.swift
Last active June 30, 2019 11:59
DeselectRowsAlongsideTransition Swift
extension UITableView {
func reloadDataAnimated() {
UIView.transition(with: self,
duration: 0.35,
options: .transitionCrossDissolve,
animations: {
self.reloadData()
})
}
@sukov
sukov / UIViewControllerExtension.swift
Last active January 4, 2019 16:30
ChangeRootViewController Swift
extension UIViewController {
func changeRootViewController(to viewController: UIViewController, animated: Bool, completion: (() -> Void)?) {
let toVC = viewController
let snapshot = UIApplication.shared.keyWindow!.snapshotView(afterScreenUpdates: true)!
let rootViewControllerChangeBlock = {
toVC.view.addSubview(snapshot)
UIApplication.shared.keyWindow?.rootViewController = toVC
let duration = animated ? 0.3 : 0
@sukov
sukov / CharacterExtension.swift
Last active January 9, 2019 13:12
Byte, Short Swift
import Foundation
extension Character {
var byte: UInt8 {
return String(self).utf8.map{UInt8($0)}[0]
}
var short: UInt16 {
return String(self).utf16.map{UInt16($0)}[0]
}