Skip to content

Instantly share code, notes, and snippets.

Ben Guo benzguo

Block or report user

Report or block benzguo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View TrendsViewModel.m
//
// PFTrendsViewModel.m
// SUM
//
// Created by Ben Guo on 11/26/14.
// Copyright (c) 2014 Project Florida. All rights reserved.
//
#import "PFTestUtilities.h"
#import "PFTrendsViewModel.h"
View address.swift
// before
func formattedAddress() -> String {
let lines:NSMutableArray = NSMutableArray(capacity: 4)
let zipStateCityArgs:NSMutableArray = NSMutableArray(capacity: 3)
let zip = self.stringValueForKeyPath("address_zip")
let city = self.stringValueForKeyPath("address_city")
let state = self.stringValueForKeyPath("address_state")
for arg in [zip, city, state] {
View enumFrom.swift
protocol StringDecodable {
init?(string: String)
}
extension Dictionary where Key: JSONKey, Value: AnyObject {
/// Converts a string to an enum value
func enumFrom<T: StringDecodable>(key: Key, _ enumType: T.Type) -> T? {
if let s = self[key] as? String {
return enumType.init(string: s)
}
View currenttype.swift
import Cocoa
protocol Pet {
var name : String { get }
func renamed(newName: String) -> Self
}
struct Fish : Pet {
let name : String
func renamed(newName: String) -> Fish {
@benzguo
benzguo / Spotify.xml
Created Apr 10, 2015
/Applications/Spotify.app/Contents/Resources/Spotify.sdef
View Spotify.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="Dictionary">
<suite name="Spotify Suite" code="spfy" description="Spotify specific classes.">
<enumeration name="ePlS" code="ePlS">
<enumerator name="stopped" code="kPSS">
<cocoa integer-value="0"/>
</enumerator>
<enumerator name="playing" code="kPSP">
<cocoa integer-value="1"/>
View mr-save-patterns.md

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) {
@benzguo
benzguo / Localization.swift
Last active Aug 29, 2015
Localize all the strings!
View Localization.swift
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: "")
}
View WWDC2014_IntegratingSwiftWithObjectiveC.md

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

View WWDC2014_AdvancedSwift.md

WWDC 2014

Extending Swift

Making something anonymous

for (key, _) in dictionary {
	println(key)
}
@benzguo
benzguo / WWDC2014_IntroToLLDBAndTheSwiftREPL.md
Created Jun 6, 2014
WWDC2014_IntroToLLDBAndTheSwiftREPL
View WWDC2014_IntroToLLDBAndTheSwiftREPL.md

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
You can’t perform that action at this time.