iphone - Get NSRange from NSRegularExpression match -


i have array contains nsrange elements.

now can last range element of array using [resultarray lastobject].

when access last element, returns unknown object. (which means unknown class)

now want cast object nsrange. how it?

my code is:

nserror *error = null; nsregularexpression *regex = [nsregularexpression regularexpressionwithpattern:parastartregex options:nsregularexpressioncaseinsensitive error:&error]; nsarray *matches = [regex matchesinstring:content options:0 range:nsmakerange(0, [content length])]; nsobject *obj =  [matches lastobject]; 

how can convert object nsrange?

if had read documentation, have noticed matchesinstring:options:range: method of nsregularexpression returns nsarray of nstextcheckingresult objects, not nsranges, it's no wonder couldn't them out directly.

additionally (and should remember future, important distinction), nsrange c struct, not objective-c object. means cannot directly stored in nsarrays or other objective-c object containers. nsarray, nsdictionary, , other objective-c classes used storing objects can store objects of objective-c types, i.e., objects instance of class , can have messages sent them [object method].

now question, array getting matchesinstring:options:range: contains nstextcheckingresult objects, contain lot more information range of match, can't cast them nsrange; need access range property of object want:

nstextcheckingresult *result = [matches lastobject]; nsrange range = [result range]; 

Comments