Comments (1)
Some of the ways I can think of are:
- Cast the array to an array of
Equatable
objects:
func contains <R: Equatable> (element: R) -> Bool {
return Swift.contains(unsafeBitCast(self, [R].self), element)
}
- Make a sequence of
Equatable
to prevent an exception in case of nonEquatable
objects in the array:
func contains <R: Equatable> (element: R) -> Bool {
let seq = SequenceOf<R> { () -> GeneratorOf<R> in
var next = 0
return GeneratorOf<R> {
var item: R? = nil
while item == nil && next < self.count {
item = self[next++] as? R
}
return item
}
}
return Swift.contains(seq, element)
}
The first implementation has the downside of being unreliable, the second one looks too complex.
from exswift.
Related Issues (20)
- NSDate extension can't support iOS7 HOT 2
- Added support for adding single elements to an array HOT 1
- Why is there a custom old interval operator? HOT 1
- Compile error caused by param mismatch for addMinutes method of NSDate HOT 2
- Dictionary merge not implemented HOT 1
- Method parameter name in groupBy
- Protocol Extensions!
- UIKit support HOT 1
- make closures parameters as @noescape when possible HOT 4
- Xcode 7 bate3 many error HOT 6
- ExSwift needs a new major version HOT 4
- Doesn't Swift-1.2 exist anymore?
- Array<any> breaks with .remove() HOT 1
- How to install it? HOT 3
- Swift 2 update issue HOT 6
- Suggestion for Boolean Extension methods(Smalltalk style conditionals) HOT 1
- This repo is not maintained anymore!!! HOT 1
- Issue with Ayn's fork HOT 4
- Swift 3 vs ExSwift.swift HOT 5
- Any plans to support swift3? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from exswift.