I guess I made the mistake of creating UIImage *image1 to UIImage *image11. Can an one advise me on how to improve it?

+(NSArray *)stampImages{
        UIImage *image1 = [UIImage imageNamed:@"abcd.png"];
        UIImage *image2 = [UIImage imageNamed:@"fron.png"];
        UIImage *image3 = [UIImage imageNamed:@"amule.png"];
        UIImage *image4 = [UIImage imageNamed:@"dog2_trans.png"];
        UIImage *image5 = [UIImage imageNamed:@"dolphin.png"];  
        UIImage *image6 = [UIImage imageNamed:@"hit.png"];  
        UIImage *image7 = [UIImage imageNamed:@"abcd.png"];
        UIImage *image8 = [UIImage imageNamed:@"qw.png"];
        UIImage *image9 = [UIImage imageNamed:@"rewq.png"];
        UIImage *image10 = [UIImage imageNamed:@"rac.png"];
        UIImage *image11 = [UIImage imageNamed:@"gs.png"];  
        UIImage *image12= [UIImage imageNamed:@"acb3.png"];   
        NSMutableArray *stampList = [NSMutableArray arrayWithObjects:image1,image2,image3,image4,image5,image6,image7,image8,image9,image10,image11,image12,nil];
        return stampList;

If you have the list of files you want to add to the array, then you can fast enumerate through them:

NSArray *fileArray; //List of file name here
NSMutableArray *stampList = [NSMutableArray array];
for (NSString *fileName in fileArray)
    [stampList addObject:[UIImage imageNamed:fileName]];
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.