[NSInvocation setArgument:atIndex:]: index (2) out of bounds [-1, 1] error with UIImageWriteToSavedPhotosAlbum? RTFM :)
Just got the following error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSInvocation setArgument:atIndex:]: index (2) out of bounds [-1, 1]'
While using: UIImageWriteToSavedPhotosAlbum
I was passing in a selector that didn't take any arguments along the lines of:
UIImageWriteToSavedPhotosAlbum([UIImage imageWithData:self.bytes], self, @selector(photoSaved), nil);
Which, if I had read the docs, I would know is wrong, since the function has to conform to the form:
- (void) image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo;
Not entirely intuitive perhaps (my expectation is that if a method expects a selector, it shouldn't dictate form and otherwise it should use a delegate; but this being a C-style function we don't have that luxury) hence this blog post in case anyone else runs into the cryptic error and is left scratching their heads.
Solution found courtesy of this post in Japanese (yeah, code's universal!) :)
Comments
by Andrew on 2009-09-29 08:31:35
by Chris on 2010-11-01 21:43:43
by nishiohirokazu on 2011-07-19 22:49:43
by Andrew on 2012-03-11 23:44:14
by Kirke on 2012-07-08 03:20:35