-
Notifications
You must be signed in to change notification settings - Fork 11
/
NilCategories.m
49 lines (40 loc) · 1.01 KB
/
NilCategories.m
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
//
// NilCategories.m
//
// Created by Vincent Gable on 2009-04-21
// Copyright 2009 Vincent Gable. All rights reserved.
//
#import "NilCategories.h"
#import "VTPG_Common.h"
@implementation NSString (NilCategories)
//builds a URL from the string
//
//+[NSURL URLWithString:] throws an exception for nil, but this is considered as designed.
- (NSURL*) convertToURL;
{
return [NSURL URLWithString:self];
}
//+[NSURL URLWithString:relativeToURL:] throws an exception
- (NSURL*) convertToURLRelitiveToURL:(NSURL*)baseURL;
{
if(!baseURL)
return nil;
return [NSURL URLWithString:self relativeToURL:baseURL];
}
@end
@implementation NSArray (NilCategories)
- (id) objectOrNilAtIndex:(NSUInteger)i;
{
if(i >= [self count] || i < 0)
return nil;
return [self objectAtIndex:i];
}
@end
@implementation NSMutableDictionary (NilCategories)
- (void) setObjectToObjectForKey:(id)key inDictionary:(NSDictionary*)otherDictionary;
{
id obj = [otherDictionary objectForKey:key];
if(obj)
[self setObject:obj forKey:key];
}
@end