ios - Expected ';' at end of declarations list error -
i declared code
nsmutablearray *allimagesarray = [[nsmutablearray alloc]init];
however error pointing @ = mark saying expected ';' @ end of declarations list error , not think occurring spacing problem. happening?
- (void) processimage:(uiimage *)image { //process captured image, crop, resize , rotate haveimage = yes; if([uidevice currentdevice].userinterfaceidiom==uiuserinterfaceidiompad) { //device ipad // resize image uigraphicsbeginimagecontext(cgsizemake(768, 1022)); [image drawinrect: cgrectmake(0, 0, 768, 1022)]; uiimage *smallimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); cgrect croprect = cgrectmake(0, 130, 768, 768); cgimageref imageref = cgimagecreatewithimageinrect([smallimage cgimage], croprect); //or use uiimage wherever [captureimage setimage:[uiimage imagewithcgimage:imageref]]; cgimagerelease(imageref); }else{ //device iphone // resize image uigraphicsbeginimagecontext(cgsizemake(320, 426)); [image drawinrect: cgrectmake(0, 0, 320, 426)]; uiimage *smallimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); cgrect croprect = cgrectmake(0, 55, 320, 320); cgimageref imageref = cgimagecreatewithimageinrect([smallimage cgimage], croprect); [captureimage setimage:[uiimage imagewithcgimage:imageref]]; cgimagerelease(imageref); } //adjust image orientation based on device orientation if ([[uidevice currentdevice] orientation] == uideviceorientationlandscapeleft) { nslog(@"landscape left image"); [uiview beginanimations:@"rotate" context:nil]; [uiview setanimationduration:0.5]; captureimage.transform = cgaffinetransformmakerotation(degreestoradians(-90)); [uiview commitanimations]; } if ([[uidevice currentdevice] orientation] == uideviceorientationlandscaperight) { nslog(@"landscape right"); [uiview beginanimations:@"rotate" context:nil]; [uiview setanimationduration:0.5]; captureimage.transform = cgaffinetransformmakerotation(degreestoradians(90)); [uiview commitanimations]; } if ([[uidevice currentdevice] orientation] == uideviceorientationportraitupsidedown) { nslog(@"upside down"); [uiview beginanimations:@"rotate" context:nil]; [uiview setanimationduration:0.5]; captureimage.transform = cgaffinetransformmakerotation(degreestoradians(180)); [uiview commitanimations]; } if ([[uidevice currentdevice] orientation] == uideviceorientationportrait) { nslog(@"upside upright"); [uiview beginanimations:@"rotate" context:nil]; [uiview setanimationduration:0.5]; captureimage.transform = cgaffinetransformmakerotation(degreestoradians(0)); [uiview commitanimations]; nsarray *directorynames = [nsarray arraywithobjects:@"hats",@"bottoms",@"right",@"left",nil]; nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; // documents folder (int = 0; < [directorynames count] ; i++) { nsstring *datapath = [documentsdirectory stringbyappendingpathcomponent:[directorynames objectatindex:i]]; if (![[nsfilemanager defaultmanager] fileexistsatpath:datapath]) [[nsfilemanager defaultmanager] createdirectoryatpath:datapath withintermediatedirectories:no attributes:nil error:nil]; //create folder nsstring *folderpath = [documentsdirectory stringbyappendingpathcomponent:@"hats"]; // "right" @ index 2, per comments & code nsstring *filepath = [filepath stringbyappendingpathcomponent:@"image_name_here.png"]; // maybe want incorporate timestamp name avoid duplicates nsdata *imagedata = uiimagepngrepresentation(captureimage.image); [imagedata writetofile:filepath atomically:yes]; } } }
for sake of clarity in discussion, mean header file (the .h file) should this:
// -------------------------------------------------------- // class header file (it has .h extension) // -------------------------------------------------------- #import <uikit/uikit.h> @interface myclass : uiviewcontroller { // ---------------------------------------------- // declare array here in header file // ---------------------------------------------- nsmutablearray *allimagesarray; } @end
and in implementation file (the .m file)
// -------------------------------------------------------- // implementation file (it has .m extension) // -------------------------------------------------------- @implementation myclass -(id)init { self = [super init]; if(self) { // ----------------------------------------------- // initialise array here // ----------------------------------------------- allimagesarray = [[nsmutablearray alloc] init]; } return self; } // rest of code @end
update
yes, can initialise array in viewdidload(). that's should :d
what saying don't write this:
nsmutablearray *allimagesarray = [[nsmutablearray alloc ]allimagesarray = [[nsmutablearray alloc] init];
that not valid syntax.
the syntax declare , initialise this:
nsmutablearray *allimagesarray = [[nsmutablearray alloc] init];
but cannot put in header file. should not this:
// -------------------------------------------------------- // class header file (it has .h extension) // -------------------------------------------------------- #import <uikit/uikit.h> @interface myclass : uiviewcontroller { // ---------------------------------------------- // don't write // ---------------------------------------------- nsmutablearray *allimagesarray = [[nsmutablearray alloc] init]; } @end
Comments
Post a Comment