From 7c06b3a314118187de2d94493680032883918ea5 Mon Sep 17 00:00:00 2001 From: Olivier Poitrey Date: Sat, 1 Oct 2011 00:38:44 +0200 Subject: [PATCH] Failsafe a very common usage error (passing URL as NSString instead of NSURL) --- SDWebImageManager.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SDWebImageManager.m b/SDWebImageManager.m index 9c6ddbc5..b9571c60 100644 --- a/SDWebImageManager.m +++ b/SDWebImageManager.m @@ -73,6 +73,13 @@ static SDWebImageManager *instance; return; } + // Very common mistake is to send the URL using NSString object instead of NSURL. For some strange reason, XCode won't + // throw any warning for this type mismatch. Here we failsafe this error by allowing URLs to be passed as NSString. + if ([url isKindOfClass:NSString.class]) + { + url = [NSURL URLWithString:(NSString *)url]; + } + // Check the on-disk cache async so we don't block the main thread [cacheDelegates addObject:delegate]; NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:delegate, @"delegate", url, @"url", [NSNumber numberWithBool:lowPriority], @"low_priority", nil];