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

Invalid bundle error while upload the app to the app Store

Saved Image in document directory and save path in coredata not able to fetch the image file iOS swift