Skip to content

Instantly share code, notes, and snippets.

View modocache's full-sized avatar

Brian Gesiak modocache

View GitHub Profile
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"user"]) {
// Type casts? I thought we were using a static language here?!
UserViewController *userViewController = (UserViewController *)segue.destinationViewController;
// I have to expose a property in order to configure the view controller.
// The view controller is in an invalid state prior to this assignment.
userViewController.user = self.selectedUser;
[self.navigationController pushViewController:userViewController animated:YES];
} else if ([segue.identifier isEqualToString:@"settings"]) {
// More of the same boilerplate...
# https://drone.io/github.com/modocache/cargo/admin
go get code.google.com/p/go.tools/cmd/cover
go get github.com/onsi/ginkgo/ginkgo
go get github.com/onsi/gomega
go get ./...
go build
$GOPATH/bin/ginkgo -r --randomizeAllSpecs -cover
package signatures
import (
"github.com/go-martini/martini"
"github.com/martini-contrib/binding"
"github.com/martini-contrib/render"
"labix.org/v2/mgo"
)
type Server *martini.ClassicMartini
@modocache
modocache / gist:da56bff7703682f6311d
Last active August 29, 2015 14:19
-[XCTest(AsynchronousTesting) expectationWithDescription:] Hangs for 70+ Seconds: A Stack Trace
Thread 1
Queue : com.apple.main-thread (serial)
#0 0x000000011062aeda in __mmap ()
#1 0x0000000110628acc in mmap ()
#2 0x0000000121178577 in ___lldb_unnamed_function567$$CoreSymbolication ()
#3 0x00000001211789bf in ___lldb_unnamed_function572$$CoreSymbolication ()
#4 0x00000001211777d2 in ___lldb_unnamed_function544$$CoreSymbolication ()
#5 0x00000001211775a7 in ___lldb_unnamed_function541$$CoreSymbolication ()
#6 0x00000001211767c0 in ___lldb_unnamed_function523$$CoreSymbolication ()
#7 0x0000000121176eae in ___lldb_unnamed_function537$$CoreSymbolication ()

Thoughts on Swift 2 Errors

When Swift was first announced, I was gratified to see that one of the (few) philosophies that it shared with Objective-C was that exceptions should not be used for control flow, only for highlighting fatal programming errors at development time.

So it came as a surprise to me when Swift 2 brought (What appeared to be) traditional exception handling to the language.

Similarly surprised were the functional Swift programmers, who had put their faith in the Haskell-style approach to error handling, where every function returns an enum (or monad, if you like) containing either a valid result or an error. This seemed like a natural fit for Swift, so why did Apple instead opt for a solution originally designed for clumsy imperative languages?

I'm going to cover three things in this post:

NSMutableArray <NSString *> *arrayOfStrings = [NSMutableArray array];
[arrayOfStrings addObject:@"hello"];
[arrayOfStrings addObject:@1]; // compiler error
[arrayOfStrings addObject:(NSString *)@1]; // OK by compiler
NSString *string = [arrayOfStrings firstObject]; // OK by compiler
NSNumber *number = [arrayOfStrings firstObject]; // compiler error
NSNumber *actuallyANumberThough = (NSNumber *)[arrayOfStrings lastObject]; // OK by compiler, and will work at runtime
@modocache
modocache / gist:82a32312af663ea59782
Created September 27, 2015 17:00
Xcode Stack Trace
Process: Xcode [59837]
Path: /Applications/Xcode-beta.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 7.1 (9069)
Build Info: IDEFrameworks-9069000000000000~10
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [59837]
User ID: 1199935289
bgesiak@bgesiak-mbp @ ~/GitHub/modocache/Argo $ ./bin/setup
==> Cloning https://github.com/Carthage/Carthage.git
==> Checking out tag 0.7.5
==> make prefix_install PREFIX=/usr/local/Cellar/carthage/0.7.5
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
CompileSwift normal x86_64 /tmp/carthage20151014-30637-1ky1qwy/Carthage/Checkouts/Runes/Source/Optional.swift
CompileSwift normal x86_64 /tmp/carthage20151014-30637-1ky1qwy/Carthage/Checkouts/Runes/Source/Array.swift
(3 failures)
make: *** [installables] Error 65
#import <Foundation/Foundation.h>
static NSString *_Nullable mightReturnAString() { /* ... */ }
static void takesANonnullString(NSString *_Nonnull string) { /* ... */ }
int main() {
// The following raises a warning when
// CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION is turned on.
takesANonnullString(mightReturnAString()); // Warning: Implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'
@modocache
modocache / gist:862528f836ddceed3fda
Created November 18, 2015 01:02
+[XCSymbolicationRecord softLinkCoreSymbolication]
char +[XCSymbolicationRecord softLinkCoreSymbolication](void * self, void * _cmd) {
if (*_softLinkCoreSymbolication.onceToken != 0xffffffffffffffff) {
dispatch_once(_softLinkCoreSymbolication.onceToken, void ^(void * _block) {
rbx = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/CoreSymbolication.framework"];
if (rbx != 0x0) {
if ([rbx loadAndReturnError:0x0] != 0x0) {
rax = dlsym(0xfffffffffffffffe, "CSIsNull");
*__XCT_CSIsNull = rax;
if (rax != 0x0) {
rax = dlsym(0xfffffffffffffffe, "CSSymbolicatorCreateWithTask");