ios - isEqual: and isKindOfClass: - Which is faster? -
ios - isEqual: and isKindOfClass: - Which is faster? -
for various reasons, in order maintain array's indexes aligned other things, have [nsnull null] within array. this:
nsarray *arr = @[obj1, obj2, obj3, [nsnull null], obj4]; there 2 methods i'm considering using when iterating through array create sure ignore null value, i'm not sure faster.
method 1
for (id obj in arr) { if (![[nsnull null] isequal:obj]) { //do stiff } } method 2
for (id obj in arr) { if ([obj iskindofclass:[myobject class]]) { //do stiff } } my question is: since i'm iterating through array appropriately handle tiled scroll view (therefore it's beingness executed many times user scrolls , it's crucial runs possible), which 1 of these methods faster?
[nsnull null] singleton, easiest things check if object pointer same.
if want fast, this:
for (id obj in arr) { if ([nsnull null]!=obj) { //do stuff } } but it's unlikely you'll see difference visual interface, talking very little difference.
an alternative discussed in comments set [nsnull null] in local variable speed checks, it's possible compiler you, i'm putting here reference:
nsobject *null_obj=[nsnull null]; (id obj in arr) { if (null_obj!=obj) { //do stuff } } ios objective-c arrays nsnull
Comments
Post a Comment