Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handlers inexistant for EGOImageLoadConnection #10

Closed
pomarec opened this issue Jun 28, 2011 · 5 comments
Closed

handlers inexistant for EGOImageLoadConnection #10

pomarec opened this issue Jun 28, 2011 · 5 comments

Comments

@pomarec
Copy link

pomarec commented Jun 28, 2011

When using blocks, app crashes when trying to use :
- (void)loadImageForURL:(NSURL_)aURL completion:(void (^)(UIImage_ image, NSURL* imageURL, NSError* error))completion;

 -[EGOImageLoadConnection handlers]: unrecognized selector sent to instance 0x5d58e00

I fixed importing EGOImageLoader.h in EGOImageLoadConnection.h

@devindoty
Copy link

Can you post a snippet of the code you're using to call loadImageForURL:completion:

@pomarec
Copy link
Author

pomarec commented Jun 29, 2011

I put this in EGOImageLoader:

- (void)loadImagesForURLs:(NSSet*)someUrls completion:(void (^)(void))completion {
    NSMutableSet *urlsToDownload = [NSMutableSet setWithSet:someUrls];
    for (NSURL *url in someUrls) {
        [self loadImageForURL:url completion:^(UIImage *image, NSURL *imageURL, NSError *error) {
            [urlsToDownload removeObject:imageURL];
            if (urlsToDownload.count == 0)
                completion();
        }];
    }
}

And called it this way :

NSMutableSet *set = [NSMutableSet set];
[set addObject:[NSURL URLWithString:@"http://myurl0"]];
[set addObject:[NSURL URLWithString:@"http://myurl1"]];
[set addObject:[NSURL URLWithString:@"http://myurl2"]];
[[EGOImageLoader sharedImageLoader] loadImagesForURLs:set completion:^(void) {
    NSLog(@"Downloads completed);
}];

@devindoty
Copy link

When you enter the loadImageForURL:completion: block, urlsToDownload is frozen by the block. You can fix this by prefixing with __block, this allows variables to be mutable in the local scope. Your NSMutableSet declaration should look like the one below.

__block NSMutableSet *urlsToDownload = [NSMutableSet setWithSet:someUrls];

http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/Blocks/Articles/bxVariables.html

@pomarec
Copy link
Author

pomarec commented Jun 29, 2011

I'm not sure but I don't think is related to this.
As I understand the issue, if you don't EGOImageLoader.h in EGOImageLoadConnection.h, __EGOIL_USE_BLOCKS is not set to 1 and 'handler' property of EGOImageLoadConnection is not defined. What do you think about it ?

@intabulas
Copy link

Issue is that the __EGOIL_USE_BLOCKS define in EGOImageLoader isnt visible to EGOImageLoadConnection

Quick hack to get it to work is to simply define it the preprocessor macros in the build settings

@pomarec pomarec closed this as completed Sep 15, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants