Skip to content
This repository was archived by the owner on Apr 15, 2019. It is now read-only.

Commit b975ead

Browse files
committed
Added ARC Support
I have added in the checks for Automatic Reference Counting by the LLVM compiler. This is just a compile-time option for the code, so that it can be used in retain/release schemes as well as ARC schemes. It's a pretty simple matter of removing the unnecessary calls that the compiler adds in anyway.
1 parent bf7eca0 commit b975ead

8 files changed

+105
-38
lines changed

NSData+Base64.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,12 @@ - (NSString *)base64EncodedString
300300
char *outputBuffer =
301301
NewBase64Encode([self bytes], [self length], true, &outputLength);
302302

303-
NSString *result =
304-
[[[NSString alloc]
305-
initWithBytes:outputBuffer
306-
length:outputLength
307-
encoding:NSASCIIStringEncoding]
308-
autorelease];
303+
NSString *result =[[NSString alloc] initWithBytes:outputBuffer
304+
length:outputLength
305+
encoding:NSASCIIStringEncoding];
306+
#if ! __has_feature(objc_arc)
307+
[result autorelease];
308+
#endif
309309
free(outputBuffer);
310310
return result;
311311
}

NSStringAdditions.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ + (NSString *)stringByGeneratingUUID {
77
CFStringRef temporaryUUIDString = CFUUIDCreateString(nil, UUIDReference);
88

99
CFRelease(UUIDReference);
10-
10+
#if ! __has_feature(objc_arc)
1111
return [NSMakeCollectable(temporaryUUIDString) autorelease];
12+
#else
13+
return (__bridge_transfer NSString*)temporaryUUIDString;
14+
#endif
1215
}
1316

1417
#pragma mark -

XMLRPCConnection.m

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,30 @@ @implementation XMLRPCConnection
3636
- (id)initWithXMLRPCRequest: (XMLRPCRequest *)request delegate: (id<XMLRPCConnectionDelegate>)delegate manager: (XMLRPCConnectionManager *)manager {
3737
self = [super init];
3838
if (self) {
39+
#if ! __has_feature(objc_arc)
3940
myManager = [manager retain];
4041
myRequest = [request retain];
4142
myIdentifier = [[NSString stringByGeneratingUUID] retain];
43+
#else
44+
myManager = manager;
45+
myRequest = request;
46+
myIdentifier = [NSString stringByGeneratingUUID];
47+
#endif
4248
myData = [[NSMutableData alloc] init];
4349

4450
myConnection = [[NSURLConnection alloc] initWithRequest: [request request] delegate: self];
4551

52+
#if ! __has_feature(objc_arc)
4653
myDelegate = [delegate retain];
54+
#endif
4755

4856
if (myConnection) {
4957
NSLog(@"The connection, %@, has been established!", myIdentifier);
5058
} else {
5159
NSLog(@"The connection, %@, could not be established!", myIdentifier);
52-
60+
#if ! __has_feature(objc_arc)
5361
[self release];
54-
62+
#endif
5563
return nil;
5664
}
5765
}
@@ -63,13 +71,21 @@ - (id)initWithXMLRPCRequest: (XMLRPCRequest *)request delegate: (id<XMLRPCConnec
6371

6472
+ (XMLRPCResponse *)sendSynchronousXMLRPCRequest: (XMLRPCRequest *)request error: (NSError **)error {
6573
NSHTTPURLResponse *response = nil;
74+
#if ! __has_feature(objc_arc)
6675
NSData *data = [[[NSURLConnection sendSynchronousRequest: [request request] returningResponse: &response error: error] retain] autorelease];
76+
#else
77+
NSData *data = [NSURLConnection sendSynchronousRequest: [request request] returningResponse: &response error: error];
78+
#endif
6779

6880
if (response) {
6981
NSInteger statusCode = [response statusCode];
7082

7183
if ((statusCode < 400) && data) {
84+
#if ! __has_feature(objc_arc)
7285
return [[[XMLRPCResponse alloc] initWithData: data] autorelease];
86+
#else
87+
return [[XMLRPCResponse alloc] initWithData: data];
88+
#endif
7389
}
7490
}
7591

@@ -79,7 +95,11 @@ + (XMLRPCResponse *)sendSynchronousXMLRPCRequest: (XMLRPCRequest *)request error
7995
#pragma mark -
8096

8197
- (NSString *)identifier {
98+
#if ! __has_feature(objc_arc)
8299
return [[myIdentifier retain] autorelease];
100+
#else
101+
return myIdentifier;
102+
#endif
83103
}
84104

85105
#pragma mark -
@@ -97,6 +117,7 @@ - (void)cancel {
97117
#pragma mark -
98118

99119
- (void)dealloc {
120+
#if ! __has_feature(objc_arc)
100121
[myManager release];
101122
[myRequest release];
102123
[myIdentifier release];
@@ -105,6 +126,7 @@ - (void)dealloc {
105126
[myDelegate release];
106127

107128
[super dealloc];
129+
#endif
108130
}
109131

110132
@end
@@ -144,7 +166,11 @@ - (void)connection:(NSURLConnection *)connection
144166
}
145167

146168
- (void)connection: (NSURLConnection *)connection didFailWithError: (NSError *)error {
169+
#if ! __has_feature(objc_arc)
147170
XMLRPCRequest *request = [[myRequest retain] autorelease];
171+
#else
172+
XMLRPCRequest *request = myRequest;
173+
#endif
148174

149175
NSLog(@"The connection, %@, failed with the following error: %@", myIdentifier, [error localizedDescription]);
150176

@@ -169,8 +195,13 @@ - (void)connection: (NSURLConnection *)connection didCancelAuthenticationChallen
169195

170196
- (void)connectionDidFinishLoading: (NSURLConnection *)connection {
171197
if (myData && ([myData length] > 0)) {
198+
#if ! __has_feature(objc_arc)
172199
XMLRPCResponse *response = [[[XMLRPCResponse alloc] initWithData: myData] autorelease];
173200
XMLRPCRequest *request = [[myRequest retain] autorelease];
201+
#else
202+
XMLRPCResponse *response = [[XMLRPCResponse alloc] initWithData: myData];
203+
XMLRPCRequest *request = myRequest;
204+
#endif
174205

175206
[myDelegate request: request didReceiveResponse: response];
176207
}

XMLRPCConnectionManager.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,17 @@ + (XMLRPCConnectionManager *)sharedManager {
4545

4646
- (NSString *)spawnConnectionWithXMLRPCRequest: (XMLRPCRequest *)request delegate: (id<XMLRPCConnectionDelegate>)delegate {
4747
XMLRPCConnection *newConnection = [[XMLRPCConnection alloc] initWithXMLRPCRequest: request delegate: delegate manager: self];
48+
#if ! __has_feature(objc_arc)
4849
NSString *identifier = [[[newConnection identifier] retain] autorelease];
50+
#else
51+
NSString *identifier = [newConnection identifier];
52+
#endif
4953

5054
[myConnections setObject: newConnection forKey: identifier];
5155

56+
#if ! __has_feature(objc_arc)
5257
[newConnection release];
58+
#endif
5359

5460
return identifier;
5561
}
@@ -100,10 +106,10 @@ - (void)finalize {
100106

101107
- (void)dealloc {
102108
[self closeConnections];
103-
109+
#if ! __has_feature(objc_arc)
104110
[myConnections release];
105-
106111
[super dealloc];
112+
#endif
107113
}
108114

109115
@end

XMLRPCDefaultEncoder.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ - (NSString *)encode {
7878
#pragma mark -
7979

8080
- (void)setMethod: (NSString *)method withParameters: (NSArray *)parameters {
81+
#if ! __has_feature(objc_arc)
8182
if (myMethod) {
8283
[myMethod release];
8384
}
@@ -97,6 +98,10 @@ - (void)setMethod: (NSString *)method withParameters: (NSArray *)parameters {
9798
} else {
9899
myParameters = [parameters retain];
99100
}
101+
#else
102+
myMethod = method;
103+
myParameters = parameters;
104+
#endif
100105
}
101106

102107
#pragma mark -
@@ -112,10 +117,12 @@ - (NSArray *)parameters {
112117
#pragma mark -
113118

114119
- (void)dealloc {
120+
#if ! __has_feature(objc_arc)
115121
[myMethod release];
116122
[myParameters release];
117123

118124
[super dealloc];
125+
#endif
119126
}
120127

121128
@end
@@ -145,7 +152,7 @@ - (NSString *)encodeObject: (id)object {
145152
return [self encodeArray: object];
146153
} else if ([object isKindOfClass: [NSDictionary class]]) {
147154
return [self encodeDictionary: object];
148-
} else if (((CFBooleanRef)object == kCFBooleanTrue) || ((CFBooleanRef)object == kCFBooleanFalse)) {
155+
} else if (((__bridge_retained CFBooleanRef)object == kCFBooleanTrue) || ((__bridge_retained CFBooleanRef)object == kCFBooleanFalse)) {
149156
return [self encodeBoolean: (CFBooleanRef)object];
150157
} else if ([object isKindOfClass: [NSNumber class]]) {
151158
return [self encodeNumber: object];

XMLRPCEventBasedParser.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ - (BOOL)isFault {
5050
#pragma mark -
5151

5252
- (void)dealloc {
53+
#if ! __has_feature(objc_arc)
5354
[myParser release];
5455
[myParserDelegate release];
5556

5657
[super dealloc];
58+
#endif
5759
}
5860

5961
@end

XMLRPCEventBasedParserDelegate.m

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ - (id)initWithParent: (XMLRPCEventBasedParserDelegate *)parent {
4949
#pragma mark -
5050

5151
- (void)setParent: (XMLRPCEventBasedParserDelegate *)parent {
52+
#if ! __has_feature(objc_arc)
5253
[parent retain];
53-
5454
[myParent release];
55+
#endif
5556

5657
myParent = parent;
5758
}
@@ -73,9 +74,10 @@ - (XMLRPCElementType)elementType {
7374
#pragma mark -
7475

7576
- (void)setElementKey: (NSString *)elementKey {
77+
#if ! __has_feature(objc_arc)
7678
[elementKey retain];
77-
7879
[myElementKey release];
80+
#endif
7981

8082
myElementKey = elementKey;
8183
}
@@ -87,9 +89,10 @@ - (NSString *)elementKey {
8789
#pragma mark -
8890

8991
- (void)setElementValue: (id)elementValue {
92+
#if ! __has_feature(objc_arc)
9093
[elementValue retain];
91-
9294
[myElementValue release];
95+
#endif
9396

9497
myElementValue = elementValue;
9598
}
@@ -101,11 +104,13 @@ - (id)elementValue {
101104
#pragma mark -
102105

103106
- (void)dealloc {
107+
#if ! __has_feature(objc_arc)
104108
[myChildren release];
105109
[myElementKey release];
106110
[myElementValue release];
107111

108112
[super dealloc];
113+
#endif
109114
}
110115

111116
@end
@@ -127,27 +132,27 @@ - (void)parser: (NSXMLParser *)parser didStartElement: (NSString *)element names
127132
[myChildren addObject: parserDelegate];
128133

129134
[parser setDelegate: parserDelegate];
130-
135+
#if ! __has_feature(objc_arc)
131136
[parserDelegate release];
132-
137+
#endif
133138
return;
134139
}
135140

136141
if ([element isEqualToString: @"array"]) {
137142
NSMutableArray *array = [[NSMutableArray alloc] init];
138143

139144
[self setElementValue: array];
140-
145+
#if ! __has_feature(objc_arc)
141146
[array release];
142-
147+
#endif
143148
[self setElementType: XMLRPCElementTypeArray];
144149
} else if ([element isEqualToString: @"struct"]) {
145150
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
146151

147152
[self setElementValue: dictionary];
148-
153+
#if ! __has_feature(objc_arc)
149154
[dictionary release];
150-
155+
#endif
151156
[self setElementType: XMLRPCElementTypeDictionary];
152157
} else if ([element isEqualToString: @"int"] || [element isEqualToString: @"i4"]) {
153158
[self setElementType: XMLRPCElementTypeInteger];
@@ -170,49 +175,49 @@ - (void)parser: (NSXMLParser *)parser didEndElement: (NSString *)element namespa
170175

171176
if ((myElementType != XMLRPCElementTypeArray) && ![self isDictionaryElementType: myElementType]) {
172177
elementValue = [self parseString: myElementValue];
173-
178+
#if ! __has_feature(objc_arc)
174179
[myElementValue release];
175-
180+
#endif
176181
myElementValue = nil;
177182
}
178183

179184
switch (myElementType) {
180185
case XMLRPCElementTypeInteger:
181186
myElementValue = [self parseInteger: elementValue];
182-
187+
#if ! __has_feature(objc_arc)
183188
[myElementValue retain];
184-
189+
#endif
185190
break;
186191
case XMLRPCElementTypeDouble:
187192
myElementValue = [self parseDouble: elementValue];
188-
193+
#if ! __has_feature(objc_arc)
189194
[myElementValue retain];
190-
195+
#endif
191196
break;
192197
case XMLRPCElementTypeBoolean:
193198
myElementValue = [self parseBoolean: elementValue];
194-
199+
#if ! __has_feature(objc_arc)
195200
[myElementValue retain];
196-
201+
#endif
197202
break;
198203
case XMLRPCElementTypeString:
199204
case XMLRPCElementTypeName:
200205
myElementValue = elementValue;
201-
206+
#if ! __has_feature(objc_arc)
202207
[myElementValue retain];
203-
208+
#endif
204209
break;
205210
case XMLRPCElementTypeDate:
206211
myElementValue = [self parseDate: elementValue];
207-
212+
#if ! __has_feature(objc_arc)
208213
[myElementValue retain];
209-
214+
#endif
210215
break;
211216
case XMLRPCElementTypeData:
212217
myElementValue = [self parseData: elementValue];
213-
218+
#if ! __has_feature(objc_arc)
214219
[myElementValue retain];
215-
220+
#endif
216221
break;
217222
default:
218223
break;
@@ -296,9 +301,9 @@ - (NSDate *)parseDateString: (NSString *)dateString withFormat: (NSString *)form
296301
[dateFormatter setDateFormat: format];
297302

298303
result = [dateFormatter dateFromString: dateString];
299-
304+
#if ! __has_feature(objc_arc)
300305
[dateFormatter release];
301-
306+
#endif
302307
return result;
303308
}
304309

0 commit comments

Comments
 (0)