Skip to content

Instantly share code, notes, and snippets.

View edc0der's full-sized avatar

Eduard Moya edc0der

  • Argentina
View GitHub Profile
@edc0der
edc0der / String+Base64.swift
Created October 20, 2017 20:21
Encode and decode base64 from String
extension String {
var base64encoded: String? {
if let data = self.data(using: .utf8) {
return data.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: 0))
}
return nil
}
@edc0der
edc0der / Generics+Utilities.swift
Created April 10, 2018 00:55
Shuffle an array in Swift
func randomizeArray<T>(_ arr: inout Array<T>) -> Void {
let maxIndex = arr.count - 1
for i in 0...maxIndex {
arr.swapAt(i, Int(arc4random_uniform(UInt32(maxIndex + 1))))
}
}
@edc0der
edc0der / Generics+Utilities.swift
Created April 10, 2018 00:56
Get class name without namespace in Swift
func className(target: AnyObject) -> String {
let nameSpaceClassName = NSStringFromClass(type(of: target))
if let className = nameSpaceClassName.components(separatedBy: ".").last {
return className
}
return ""
}
@edc0der
edc0der / ActivityIndicatorOverlay.swift
Last active December 17, 2023 13:37
iOS + Swift: Display activity indicator overlay - UIViewController extension
import UIKit
fileprivate let overlayViewTag: Int = 999
fileprivate let activityIndicatorViewTag: Int = 1000
// Public interface
extension UIView {
func displayAnimatedActivityIndicatorView() {
setActivityIndicatorView()
}