Skip to content

Instantly share code, notes, and snippets.

View vprtwn's full-sized avatar
🌀
𓊍

Ben Guo vprtwn

🌀
𓊍
View GitHub Profile
@vprtwn
vprtwn / README.md
Last active June 30, 2022 14:33
Force Directed Graph Editor

Drag from an existing node to add a new node or link. Hit the DELETE key to remove the selected node or link.

Built with D3.js.

@vprtwn
vprtwn / README.md
Last active July 3, 2023 14:07
Force Editor + Pan/Zoom

Drag from an existing node to add a new node or link. Click to select/deselect nodes/links. Hit the DELETE key to remove the selected node or link. Drag to pan. Scroll to zoom.

Built with D3.js.

New iTunes Connect

Analytics

Metrics

  • app store views
  • installs
  • sessions
  • active devices
  • retention
  • stickiness

WWDC 2014 Brain Lanier

Optionals

  • Cleaner alternative to using sentinels (NULL, NSNotFound, etc.) to represent invalid values
  • optionals are initialized to nil by default
    • var optionalNumber: Int?
  • nil is a sentinel value that works with any type
  • value is wrapped in optional by setter
    • optionalNumber = 6

Working with Cocoa

Implicitly Unwrapped Optionals

  • A value of class type in Swift is never nil
    • var fileModificationDate: NSDate!
  • Objective-C does not have a notion of a "never-nil" pointer
  • ! is an implicitly unwrapped optional
    • can be tested explicitly for nil
    • can directly access properties/methods of the underlying value
    • can be implicitly converted to its underlying value
@vprtwn
vprtwn / WWDC2014_IntroToLLDBAndTheSwiftREPL.md
Created June 6, 2014 23:45
WWDC2014_IntroToLLDBAndTheSwiftREPL

Intro To LLDB and the Swift REPL

Sean Callanan

Basic debugging

  • lldb commands
    • ti/ thread info
      • EXC_BAD_INSTRUCTION = CPU doesn't understand an instruction
        • typically used in assertions -> Assertion failure
    • bt / thread backtrace
  • prints all frames on the stack of the current thread

WWDC 2014

Extending Swift

Making something anonymous

for (key, _) in dictionary {
	println(key)
}

Integrating Swift With Objective-C

Introduction

  • Swift is modern, type-safe, expressive, performant

  • but Objective-C remains a first-class citizen

  • Same design patterns, Cocoa APIs

  • "We do not want you to rewrite or stop improving your existing code!"

  • Should you use unowned or weak for delegates?

  • To expose Objective-C to Swift, use a bridging header

@vprtwn
vprtwn / Localization.swift
Last active August 29, 2015 14:05
Localize all the strings!
import Foundation
infix operator | {}
func | (lhs: String, rhs: String) -> String {
return NSLocalizedString(lhs, comment: rhs)
}
postfix operator | {}
postfix func | (s: String) -> String {
return NSLocalizedString(s, comment: "")
}

Common Save Patterns

Standard background save

Assuming that you don't care which NSManagedObjectContext is used, and you just want to make some changes and save them in the background, use the following method. 90% of the time, this is what you'll want.

NSManagedObjectSubclass *myObject = [NSManagedObjectSubclass MR_findFirst];

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {