Skip to content

Instantly share code, notes, and snippets.

View kiwiswift's full-sized avatar

Christiano Gontijo kiwiswift

View GitHub Profile
@kiwiswift
kiwiswift / Persistence.swift
Created October 15, 2023 08:49
Creates a NSPersistentContainer that allows multiple data stores with different name
import CoreData
struct PersistenceController {
let container: NSPersistentContainer
init(userName: String,
inMemory: Bool = false) {
// Both the store and data model can be any string, for the sake of simplicity lets
@kiwiswift
kiwiswift / generateRandomDate.swift
Last active August 4, 2021 01:48 — forked from edmund-h/generateRandomDate.swift
A function to create a random date in Swift 3
// credit to @eirnym, adapted this from their OBJC code: https://gist.github.com/eirnym/c9526a045556e4d8464b41a367843e3c
// generates a random date and time in the past, limited by daysBack (a number of days before today)
// also generates a random time to go with that date.
// original request: http://stackoverflow.com/questions/10092468/how-do-you-generate-a-random-date-in-objective-c
func generateRandomDate(daysBack: Int)-> Date?{
let day = arc4random_uniform(UInt32(daysBack))+1
@kiwiswift
kiwiswift / script.sh
Created April 24, 2018 04:43 — forked from tonylukasavage/script.sh
Move all uncommitted changes to a new branch and revert the existing branch to HEAD. "master" has uncommitted changes. You decided you'd rather make those changes in "dev_branch". Here's how to move those uncommitted changes to "dev_branch" and then revert "master" to its last commit.
# get into the master branch
git checkout master
# create a new branch for the changes and check it out
git checkout -b dev_branch
# stash the changes until we revert master
git stash
# go back to master