I'm trying to add an extension on optional arrays so I can do this
var test: [String]? XCTAssert(test.isNilOrEmpty) test = [] XCTAssert(test.isNilOrEmpty) test = ["abc"] XCTAssertFalse(test.isNilOrEmpty)
I cannot get the extension syntax correct, this is what I'm trying:
extension Optional where Wrapped: Array { // Error: Reference to generic type 'Array' requires arguments in <...> var isNilOrEmpty: Bool { self?.isEmpty ?? true } }
I tried using Array<Any>
but didn't let me apply to any type. What's the right syntax do achieve this?
没有评论:
发表评论