Skip to content

Instantly share code, notes, and snippets.

View vprtwn's full-sized avatar
🌀
𓊍

Ben Guo vprtwn

🌀
𓊍
View GitHub Profile
//
// 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"

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

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) {
@vprtwn
vprtwn / Spotify.xml
Created April 10, 2015 03:51
/Applications/Spotify.app/Contents/Resources/Spotify.sdef
<?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"/>
import Cocoa
protocol Pet {
var name : String { get }
func renamed(newName: String) -> Self
}
struct Fish : Pet {
let name : String
func renamed(newName: String) -> Fish {