0

I have an array of [myObject] called myArray and an myObject object.

I want to check if myObject is the last object in myArray.

What is the best way to do it?

I've tried:

if myObject == myArray.last!

but it gives me this error:

Binary operator '==' cannot be applied to two 'myObject' operands

Any idea? Thanks!

F.SO4
  • 167
  • 2
  • 9

1 Answers1

-1

Try this one may be work for you.

let ary = ["1","2","3"]

if ary[0].isEqual(ary.last!){
    print("Is last object")
}else{
    print("Is Not last object")
}

Your output should be:Is Not last object

let ary = ["1"]

if ary[0].isEqual(ary.last!){
    print("Is last object")
}else{
    print("Is Not last object")
}

Your output should be:Is last object

Hitesh Surani
  • 12,733
  • 6
  • 54
  • 65