NSFileManager documents & caches extension


Here’s a handy little NSFileManager extension that gives you easy access to the documents and caches directories for your app…

import Foundation

extension NSFileManager {
	class func documentsDir() -> String {
		var paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) as [String]
		return paths[0]
	class func cachesDir() -> String {
		var paths = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true) as [String]
		return paths[0]

ALAMOFIRE: the AFNetworking written in Swift

Alamofire is an HTTP networking library written in Swift.

Alamofire is available on github under MIT License.
Its documentation is available on nshipster too.

Mattt Thomphson rewrote the AFNetworking library for Swift: Alamofire.

Alamofire leverages NSURLSession and the Foundation URL Loading System to provide first-class networking capabilities in a convenient Swift interface.


  • Chainable Request / Response methods
  • URL / JSON / plist Parameter Encoding
  • Upload File / Data / Stream
  • Download using Request or Resume data
  • Authentication with NSURLCredential
  • Progress Closure & NSProgress
  • cURL Debug Output
  • 100% Unit Test Coverage
  • Complete Documentation
  • HTTP Response Validation
  • TLS Chain Validation
  • UIKit / AppKit Extensions

  • Xcode 6
  • iOS 7.0+ / Mac OS X 10.9+


  • Just drag & drop the Alamofire.swift file into your Swift project.

Getting started with Alamofire is easy:

  • GET
    Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"])
             .response { (request, response, data/string/JSON, error) in
  • POST
    Alamofire.request(.POST, "http://httpbin.org/get", parameters: ["foo": "bar"], encoding: .JSON(options: nil))
    let user = "user"
    let password = "password"
    Alamofire.request(.GET, "https://httpbin.org/basic-auth/\(user)/\(password)")
        .authenticate(HTTPBasic: user, password: password)
        .response {(request, response, _, error) in

Alamofire is available on github under MIT License. 

Of course, AFNetworking remains the premiere networking library available for Mac OS X and iOS, and can easily be used in Swift, just like any other Objective-C code. AFNetworking is stable and reliable, and isn’t going anywhere. But for anyone looking for something a little more idiomatic to Swift, Alamofire may be right up your alley. (It’s not a mutually-exclusive choice, either! AFNetworking & Alamofire will peacefully co-exist within the same codebase.)

Not supported characters in Objective-C and Swift

Swift provides a variant of the @objc attribute that allows you to specify name for your symbol in Objective-C.
For example, if the name of your Swift class contains a character that isn’t supported by Objective-C, you can provide an alternative name to use in Objective-C.
If you provide an Objective-C name for a Swift function, use Objective-C selector syntax.
Remember to add a colon (:) wherever a parameter follows a selector piece.
  class Белка {
     init (имя: String) { /*...*/ }    
     func прячьОрехи(Int, вДереве: Дерево) { /*...*/ }