| //#!/usr/bin/env objc-run | |
| #import <Foundation/Foundation.h> | |
| #import <objc/runtime.h> | |
| #import <objc/message.h> | |
| /// | |
| /// Typedefs | |
| typedef id (^TargetMethod)(id arg); |
| // Basically, these are if and else statements respectively | |
| // without the opposite clause | |
| func when(test: @autoclosure () -> Bool, action: () -> ()) { | |
| if test() { action() } | |
| } | |
| func unless(test: @autoclosure () -> Bool, action: () -> ()) { | |
| if !test() { action() } | |
| } |
| // meet Stringy - a simple string type with a fluent interface | |
| struct Stringy { | |
| let content: String | |
| init(_ content: String) { | |
| self.content = content | |
| } | |
| func append(appendage: Stringy) -> Stringy { |
| // SO [UITextView - Highlight text with NSBackgroundColor - exclude line breaks](http://stackoverflow.com/questions/26558396/uitextview-text-highlighting-when-the-text-is-centered) | |
| // Source | |
| // TextViewHighlighter.h | |
| #import <Foundation/Foundation.h> | |
| @import UIKit; | |
| @interface TextViewHighlighter : NSObject |
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:
Here's my own list of the interesting stuff announced during this year's WWDC, collected from the keynotes, various Apple docs, blog posts and tweets.
If you're planning to watch the videos, I really recommend this Mac app that helps you download and watch them: https://github.com/insidegui/WWDC.
http://www.apple.com/osx/elcapitan-preview/
- split view - two apps side by side on full screen
| // CacheItem.h | |
| @interface CacheItem : RLMObject | |
| @property NSString *key; | |
| @property NSData *value; | |
| @end | |
| // CacheItem.m | |
| @implementation CacheItem |
Starting from iOS 9, App Transport Security enforces to use secure HTTPS requests by default.
App Transport Security
App Transport Security (ATS) enforces best practices in the secure connections between an app and its back end. ATS prevents accidental disclosure, provides secure default behavior, and is easy to adopt; it is also on by default in iOS 9 and OS X v10.11. You should adopt ATS as soon as possible, regardless of whether you’re creating a new app or updating an existing one.
If you’re developing a new app, you should use HTTPS exclusively. If you have an existing app, you
| import Foundation | |
| class ThrottleHandler { | |
| let interval: NSTimeInterval | |
| let block: dispatch_block_t | |
| private var source: dispatch_source_t? | |
| init(interval: NSTimeInterval, block: dispatch_block_t) { | |
| self.interval = interval |