comparing arrays in objective-c

前端 未结 5 2006
梦谈多话
梦谈多话 2020-12-09 11:24

Ok a pretty simple question.. in c++ it seems to work but in objective-c i seem to struggle with it :S .. If you want to compare two arrays it should be something like thi

5条回答
  •  青春惊慌失措
    2020-12-09 12:00

    I do the following when comparing arrays:

    • Check to see if any of the arrays are nil when the other is not
    • Check to see if the lengths are the same
    • Iterate (using a for loop like you have) over each element checking the matching element in the other array.

    To compare elements you need to define what you want to regard as being "equal". Are they equal only if the pointers in the array are equal or can they be equal if the content is equal too.

    For the pointer case, you can use ==.

    For the deep comparison you might need to use CompareTo or something similar.

提交回复
热议问题