Compare array contains same object iOS swift

 Solution:

We had an option that will compare single array with its object's all are equal or different.

In that we can use "Set" function like below.

Code:

let myArrayA = [1,2,3]

let myArrayB = [1,1,1]

If(Set(myArrayA).count == myArrayA.count) {
print("different")

} else {

print("same")

If(Set(myArrayB).count == myArrayB.count) {
print("different")

} else {

print("same")


The first one returns different and the second one returns same...Happy coding....

Comments

Popular posts from this blog

Convert NsNumber, NSDate to String in iOS Swift

store cgpoint in userdefaults iOS swift