Swifterswift: Add more Optional extensions

Created on 30 Mar 2018  路  2Comments  路  Source: SwifterSwift/SwifterSwift

Add more Optional extensions:

// check if optional is nil or empty collection
public extension Optional where Wrapped: Collection {
    public var isNilOrEmpty: Bool { ... }
}

Here are some unit tests to include to check if you've done this correctly:

func testIsNilOrEmpty() {
   let nilArray: [String]? = nil
   XCTAssertTrue(nilArray.isNilOrEmpty)
   let emptyArray: [String] = []
   XCTAssertTrue(emptyArray.isNilOrEmpty)
   let intArray: [Int] = [1]
   XCTAssertFalse(intArray.isNilOrEmpty)
   let optionalArray: [Int]? = [1]
   XCTAssertFalse(optionalArray.isNilOrEmpty)
}
good first issue new extension

Most helpful comment

String is a collection :trollface:

All 2 comments

String is a collection :trollface:

Didn't know Github has a :trollface: emoji 馃槀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omaralbeik picture omaralbeik  路  5Comments

omaralbeik picture omaralbeik  路  3Comments

omaralbeik picture omaralbeik  路  3Comments

g001613001 picture g001613001  路  5Comments

pawurb picture pawurb  路  3Comments