Skip to content

Instantly share code, notes, and snippets.

@jpsim
jpsim / code.m
Last active December 25, 2015 20:39
UIProgressView Always Animates
UIProgressView *v = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
v.frame = CGRectMake(40, 100, 240, 2);
[self.view addSubview:v];
{
double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[v setProgress:0.5f animated:NO];
});
@jpsim
jpsim / NSCFCalendar Error
Created October 18, 2013 18:59
NSCFCalendar Error
-[__NSCFCalendar components:fromDate:]: date cannot be nil
I mean really, what do you think that operation is supposed to mean with a nil date?
An exception has been avoided for now.
A few of these errors are going to be reported with this complaint, then further violations will simply silently do whatever random thing results from the nil.
@jpsim
jpsim / switch.swift
Last active April 15, 2016 22:03
optional enum switch compiler issue
enum MyEnum {
case Case1, Case2
}
let myEnum: MyEnum? = .Case1
// Implicit optional unwrapping
// These first two case statements fail to compile:
//
@jpsim
jpsim / realm_write_syntax.swift
Created November 14, 2015 00:16
Realm.write() valid syntax
import RealmSwift
// Swift's syntax allows for a variety of ways to invoke closures.
// Here are some of them, specifically ways to making write transactions in Realm Swift.
// See https://realm.io/docs/swift/latest/#writes for Realm's docs on write transactions.
do {
let realm = try Realm()
// 1

Keybase proof

I hereby claim:

  • I am jpsim on github.
  • I am jpsim (https://keybase.io/jpsim) on keybase.
  • I have a public key ASBwmCI1FZ8tNZxDyhrZwx06OrlGAWufb1hQDmLWXD7IWgo

To claim this, I am signing this object:

@jpsim
jpsim / Person.swift
Created July 29, 2015 18:59
Representing an array of strings in Realm
/**
Although this example demonstrates how to store flat arrays of strings
on a Realm model, you can extend this pattern to store anything from
arrays of integers to native Swift enum's. Basically anything that you can
map to a representable type in Realm.
*/
class RealmString : Object {
dynamic var stringValue = ""
}
@jpsim
jpsim / README.md
Last active January 18, 2018 11:23
Generate Swift docs on Linux with Jazzy and SourceKitten
@jpsim
jpsim / MyTableViewController.m
Created August 19, 2014 22:57
Grouped UITableView using Realm
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2014 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
@jpsim
jpsim / TranslatedString.swift
Created June 4, 2016 20:59
TranslatedString Realm Model
// Example approach for modeling localized strings in Realm
import Foundation
import RealmSwift
enum Locale: String {
case English = "en"
case French = "fr"
}
@jpsim
jpsim / swift_dev_linux.md
Created December 14, 2017 18:18
Build & run a subset of Swift tests on Linux

Build & run a subset of Swift tests on Linux

# Spin up a beefy Digital Ocean droplet
doctl compute droplet create swift-dev --size m-224gb --image ubuntu-16-10-x64 --region sfo2 --ssh-keys XXXXXXX
doctl compute ssh swift-dev
# Install dependencies
apt-get update
apt-get install git cmake ninja-build clang python uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev autoconf libtool systemtap-sdt-dev tzdata
# Clone & build Swift