Skip to content

Instantly share code, notes, and snippets.

@samrayner
samrayner / Realm+CascadeDeleting.swift
Last active Jun 24, 2021 — forked from krodak/Realm+CascadeDeleting.swift
Cascading deletion for RealmSwift
View Realm+CascadeDeleting.swift
import Foundation
import RealmSwift
import Realm
//Forked from: https://gist.github.com/krodak/b47ea81b3ae25ca2f10c27476bed450c
internal protocol CascadingDeletable: RealmSwift.Object {
static var propertiesToCascadeDelete: [String] { get }
}
@davidlawson
davidlawson / BadgeBarButtonItem.swift
Last active Dec 8, 2021
UIBarButtonItem with badge, Swift 4, iOS 9/10/11
View BadgeBarButtonItem.swift
import UIKit
public class BadgeBarButtonItem: UIBarButtonItem
{
@IBInspectable
public var badgeNumber: Int = 0 {
didSet {
self.updateBadge()
}
}
@valvoline
valvoline / String+HTML.swift
Created Nov 8, 2017
A swift string extension to deal with HTML
View String+HTML.swift
//
// String+HTML.swift
// AttributedString
//
// Created by Costantino Pistagna on 08/11/2017.
// Copyright © 2017 sofapps.it All rights reserved.
//
import UIKit
import Foundation
@troyfontaine
troyfontaine / 1-setup.md
Last active May 18, 2022
Signing your Git Commits using GPG on MacOS Sierra/High Sierra
View 1-setup.md

Methods of Signing with GPG

Last updated March 28, 2021

There are now two ways to approach this:

  1. Using gpg and generating keys
  2. Using Kryptonite by krypt.co

This Gist explains how to do this using gpg in a step-by-step fashion. Kryptonite is actually wickedly easy to use-but you will still need to follow the instructions

@JohnSundell
JohnSundell / Perform.swift
Last active Dec 21, 2019
A function that enables you to easily wrap throwing APIs, to provide a custom error
View Perform.swift
/**
* Perform a throwing expression, and throw a custom error in case the expression threw
*
* - parameter expression: The expression to execute
* - parameter error: The custom error to throw instead of the expression's error
* - throws: The given error
* - returns: The return value of the given expression
*/
func perform<T>(_ expression: @autoclosure () throws -> T, orThrow errorExpression: @autoclosure () -> Error) throws -> T {
do {
@joshdholtz
joshdholtz / StopJumpingTableViewOnInsertRows.swift
Last active Jan 18, 2022
Used when loading more data into UITableView for a smooth "infinite scroll" feel
View StopJumpingTableViewOnInsertRows.swift
// I dont want my table jumping/animation when appending new rows
// for an infinite scroll feel
//
// Some of this might not be needed but it works
//
// TODO: Possibly garbage
extension UITableView {
func reloadDataSmoothly() {
UIView.setAnimationsEnabled(false)
@insidegui
insidegui / WebCacheCleaner.swift
Created Sep 14, 2016
Clear WKWebView's cookies and website data storage, very useful during development.
View WebCacheCleaner.swift
import Foundation
import WebKit
final class WebCacheCleaner {
class func clean() {
HTTPCookieStorage.shared.removeCookies(since: Date.distantPast)
print("[WebCacheCleaner] All cookies deleted")
WKWebsiteDataStore.default().fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records in
@chrisjlee
chrisjlee / delete-feature-branches.sh
Last active Mar 30, 2022
Delete feature branch with prefix locally then remove all remote feature branches
View delete-feature-branches.sh
# Stole from:
# http://stackoverflow.com/questions/32122784/alias-script-to-delete-all-local-and-remote-git-branches-with-a-specific-prefix
git branch -D $(printf "%s\n" $(git branch) | grep 'feature/')
# Or this will work too to remove all remote branches:
# https://coderwall.com/p/eis0ba/remove-a-thousand-stale-remote-branches-on-git
git branch -r | awk -F/ '/\/feature/{print $2}' | xargs -I {} git push origin :{}
# Prune all origin branches
git remote prune origin
@davbeck
davbeck / assets.rb
Last active Jan 5, 2022
Automatic Enum-based Xcassets in Swift
View assets.rb
#!/usr/bin/env ruby
require "active_support"
def assetCatalogsAtPath(path)
results = []
contents = Dir.entries(path)
@snikch
snikch / gist:3661188
Created Sep 6, 2012
Find the current top view controller for your iOS application
View gist:3661188
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}