Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 56 lines (41 sloc) 1.42 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
//
// NSArray+DTError.m
// DTFoundation
//
// Created by Oliver Drobnik on 6/15/10.
// Copyright 2010 Drobnik.com. All rights reserved.
//

#import "NSArray+DTError.h"

// force this category to be loaded by linker
MAKE_CATEGORIES_LOADABLE(NSArray_DTError);

@implementation NSArray (DTError)


+ (NSArray *)arrayWithContentsOfURL:(NSURL *)url error:(NSError **)error
{
NSData *readData = [NSData dataWithContentsOfURL:url];

CFStringRef errorString = NULL;

CFPropertyListRef plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
(__bridge CFDataRef)readData,
kCFPropertyListImmutable,
(CFStringRef *)&errorString);

if (plist)
{
NSArray *readArray = [NSArray arrayWithArray:(__bridge id)plist];
CFRelease(plist);

return readArray;
}

if (errorString&&error)
{
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *domain = [infoDict objectForKey:(id)kCFBundleIdentifierKey];

NSDictionary *userInfo = [NSDictionary dictionaryWithObject:(__bridge NSString *)errorString
forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:domain code:1 userInfo:userInfo];
}

return nil;
}

+ (NSArray *)arrayWithContentsOfFile:(NSString *)path error:(NSError **)error
{
NSURL *url = [NSURL fileURLWithPath:path];
return [NSArray arrayWithContentsOfURL:url error:error];
}


@end
Something went wrong with that request. Please try again.