Suppose I have an array having elements "am","john","rosa","freedom". I want to compare these elements and result would be the word and the size of the longest word. I am using objective C.
Suppose I have an array having elements am,john,rosa,freedom . I want to compare these
Share
There isn’t a “built-in” way of doing this, however you can use
NSArray‘ssortedArrayUsingSelector:and create a category onNSStringto provide alengthCompare:method.Now you can sort an of strings in ascending order using
lengthCompare: