JPMartha's Pancake

This blog is the way to brush up my poor English.

#swiftlang ? Examples of Swift 2.2 & 3.0 Compatibility


Result 2.0.0 was released. ?

It has already supported Swift 3.0. ?

Then, I tried Swift 3.0 in other project! ? It means Swift 2.2 and 3.0 Compatibility. ?

By the way, I don't google it. So, if there are some mistakes, please feel free to correct them. ?

Result 2.0.0Swift 3.0 対応 されたので自分もやってみました。?

といっても手元の環境で動いただけなのであやしいですけどね。 ?

せっかくなので事例として残しておきます。✍️

ググってないのでもし間違ってたら教えてください。 ?

Environment

Example of SE-0006:

Apply API Guidelines to the Standard Library

ErrorType ? ErrorProtocol

#if swift(>=3.0)
    public typealias PancakeErrorType = ErrorProtocol
#else
    public typealias PancakeErrorType = ErrorType
#endif

Generator ? Iterator / CollectionType ? Collection

#if swift(>=3.0)
    func pancake<C: Collection where C.Iterator.Element == String>
#else
    func pancake<C: CollectionType where C.Generator.Element == String>
#endif

これは Result 2.0.0パクリ 参考にし ました。

init(count: Int, repeatedValue: Element) ? init(repeating: Element, count: Int)

#if swift(>=3.0)
    let sweets = repeatElement(pancake, count: 500)
#else
    let sweets = Array(count: 500, repeatedValue: pancake)
#endif

Example of SE-0011:

Replace typealias keyword with associatedtype for associated type declarations

typealias ? associatedtype

typealias PancakeType = Self

associatedtype PancakeType = Self

Example of SE-0040:

Replacing Equal Signs with Colons For Attribute Arguments

= ? :

#if swift(>=3.0)
    @available(*, deprecated, message:"...")
#else
    @available(*, deprecated, message="...")
#endif

XCTest

#if swift(>=3.0)
    measure({ 
        ...
    })
#else
    measureBlock {
        ...
    }
#endif

Reference