ios - NSRangeException when searching for bytes near end of NSData -


i want check last 2 bytes of files in app make sure not corrupt .jpg's

rangeofdata:options:range: looks option, having hard time figuring out how proper nsrange. range looking starting near end of nsdata, end.

here have far:

nsdata *imagedata = [nsdata datawithcontentsoffile:filepath]; nsrange range = {([imagedata length]-8),[imagedata length]}; nsstring *str = @"ffd9"; nsdata *jpgtest = [str datausingencoding:nsutf8stringencoding]; nsrange found = [imagedata rangeofdata:jpgtest options:nsdatasearchbackwards range:range]; 

here error get:

** terminating app due uncaught exception 'nsrangeexception', reason: '*** -[nsconcretedata rangeofdata:options:range:]: range {14954, 14962} enxceeds data length 14962'

how range search last few bytes of nsdata?

the second member of nsrange not end point of range length. in case should be:

nsrange range = {([imagedata length]-8), 8}; 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -