This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension NSManagedObjectContext { | |
| //MARK: - Public Properties | |
| public class var defaultContext: NSManagedObjectContext! { | |
| get { | |
| let context = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.MainQueueConcurrencyType) | |
| context.persistentStoreCoordinator = self.persistentStoreCoordinator // This provided by more extension properties | |
| return context | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Ever find yourself having to extract image from a lump of HTML. Can't use a XML parser (even in HTML mode) because the raw HTML is too broken. I've been there, and devised this function using Regular Expressions as a fall back option. | |
| */ | |
| - (NSArray *) extractSuitableImagesFromRawHTML:(NSString *)rawHTML { | |
| NSMutableArray * images = [[NSMutableArray alloc] init]; | |
| if (rawHTML != nil && [rawHTML length] != 0) { | |
| NSRegularExpression * regex = [[NSRegularExpression alloc] initWithPattern:@"<\\s*?img\\s+[^>]*?\\s*src\\s*=\\s*([\"\'])((\\\\?+.)*?)\\1[^>]*?>" options:NSRegularExpressionCaseInsensitive error:nil]; | |
| NSArray * imagesHTML = [regex matchesInString:rawHTML options:0 range:NSMakeRange(0, [rawHTML length])]; | |
| [regex release]; |