Skip to content

Instantly share code, notes, and snippets.

View av0c0der's full-sized avatar
🏠
Working from home

avocoder av0c0der

🏠
Working from home
  • Istanbul, Turkiye
View GitHub Profile
@av0c0der
av0c0der / Menu.swift
Created December 23, 2021 09:42
UIMenu builder with iOS < 13 fallback using UIAlertController
import UIKit
public enum MenuImageType {
case bundled(_ name: String, bundle: Bundle = .main)
case symbol(_ name: String)
var image: UIImage? {
switch self {
case .bundled(let name, let bundle):
return UIImage(named: name, in: bundle, compatibleWith: .none)
@av0c0der
av0c0der / UIView+Snapshot.swift
Last active January 23, 2019 10:13 — forked from dsowsy/Snapshot.swift
Create snapshots with ease
import UIKit
extension UIView {
/// Creates a bitmap-based graphics context with the specified options
///
/// - Parameters:
/// - size: The size (measured in points) of the new bitmap context (view bounds' size used by default). This represents the size of the image returned by the UIGraphicsGetImageFromCurrentImageContext() function. To get the size of the bitmap in pixels, you must multiply the width and height values by the value in the scale parameter.
/// - opaque: A Boolean flag indicating whether the bitmap is opaque (default is `true`). If you know the bitmap is fully opaque, specify true to ignore the alpha channel and optimize the bitmap’s storage. Specifying false means that the bitmap must include an alpha channel to handle any partially transparent pixels.
/// - scale: The scale factor to apply to the bitmap. If you specify a value of 0.0 (default), the scale factor is set to the scale factor of the device’s main screen.
//
// CLLocation+Validate.swift
// CocoaExtensions
//
// Created by Abdurahim Jauzee on 21/12/2018.
// https://medium.com/@mizutori/make-it-even-better-than-nike-how-to-filter-locations-tracking-highly-accurate-location-in-774be045f8d6
import Foundation
import CoreLocation
@av0c0der
av0c0der / AllEnumCases.swift
Created December 29, 2017 23:24
Get all Enum cases if RawValue is Int
private enum Field: Int {
case name, city, state, zip, country, phone
static var all: [Field] {
var fields: [Field] = []
var raw = 0
while let field = Field(rawValue: raw) {
fields.append(field)
raw += 1
}
@av0c0der
av0c0der / NSRange.swift
Created February 4, 2017 20:23
Creating NSRange from Swift String
import UIKit
let stringWithEmoji = "النَّظافَةُ ضَرورِيَّةٌ في كُلِّ شَىءٍ 💧"
let rangeFromCharacters = NSMakeRange(0, stringWithEmoji.characters.count)
let rangeFromUtf16 = NSMakeRange(0, stringWithEmoji.utf16.count)
rangeFromCharacters.length // 26
rangeFromUtf16.length // 77
@av0c0der
av0c0der / UIEdgeInsets.swift
Last active August 19, 2016 19:14
Some convenient initializers for UIEdgeInsets
import UIKit
extension UIEdgeInsets {
// let insets = UIEdgeInsets(15)
// —> UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15)
public init(_ padding: CGFloat) {
top = padding
bottom = padding
left = padding