swift - Comparing array of force unwrapped optionals -
i'm writing test:
func test_arrayfromshufflingarray() { var videos = [mockobjects.mockvmvideo_1(), mockobjects.mockvmvideo_2(), mockobjects.mockvmvideo_3()] let tuple = shufflehelper.arrayfromshufflingarray(videos, currentindex:1) var shuffledvideos = tuple.0 let shuffleindexmap = tuple.1 // -- test order different xctassert(videos != shuffledvideos, "test_arrayfromshufflingarray fail") }
but on last line last line:
binary operator '!=' cannot applied 2 '[vmvideo!]' operands
arrays can compared ==
if element type equatable
:
/// returns true if these arrays contain same elements. public func ==<element : equatable>(lhs: [element], rhs: [element]) -> bool
but neither implicitlyunwrappedoptional<wrapped>
nor optional<wrapped>
conform equatable
, if underlying type wrapped
does.
possible options (assuming vmvideo
conforms equatable
):
change code
videos
,shuffledvideos
[vmvideo]
arrays instead of[vmvideo!]
.compare arrays elementwise:
xctassert(videos.count == shuffledvideos.count && !zip(videos, shuffledvideos).contains {$0 != $1 })
define
==
operator arrays of implicitly unwrapped equatable elements:func ==<element : equatable> (lhs: [element!], rhs: [element!]) -> bool { return lhs.count == rhs.count && !zip(lhs, rhs).contains {$0 != $1 } }
Comments
Post a Comment