Skip to content

Commit b023d6b

Browse files
author
Antoine Marcadet
committed
Updating properties to use the "auto-synthesized property" feature appeared in Xcode 4.4
1 parent 2540c46 commit b023d6b

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

XMLReader.h

-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ enum {
1616
typedef NSUInteger XMLReaderOptions;
1717

1818
@interface XMLReader : NSObject <NSXMLParserDelegate>
19-
{
20-
NSMutableArray *dictionaryStack;
21-
NSMutableString *textInProgress;
22-
NSError *errorPointer;
23-
}
2419

2520
+ (NSDictionary *)dictionaryForXMLData:(NSData *)data error:(NSError **)errorPointer;
2621
+ (NSDictionary *)dictionaryForXMLString:(NSString *)string error:(NSError **)errorPointer;

XMLReader.m

+17-18
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717

1818
@interface XMLReader ()
1919

20-
- (id)initWithError:(NSError **)error;
21-
- (NSDictionary *)objectWithData:(NSData *)data options:(XMLReaderOptions)options;
20+
@property (nonatomic, strong) NSMutableArray *dictionaryStack;
21+
@property (nonatomic, strong) NSMutableString *textInProgress;
22+
@property (nonatomic, strong) NSError *errorPointer;
2223

2324
@end
2425

@@ -61,20 +62,19 @@ - (id)initWithError:(NSError **)error
6162
self = [super init];
6263
if (self)
6364
{
64-
errorPointer = *error;
65+
self.errorPointer = *error;
6566
}
6667
return self;
6768
}
6869

6970
- (NSDictionary *)objectWithData:(NSData *)data options:(XMLReaderOptions)options
7071
{
7172
// Clear out any old data
72-
73-
dictionaryStack = [[NSMutableArray alloc] init];
74-
textInProgress = [[NSMutableString alloc] init];
73+
self.dictionaryStack = [[NSMutableArray alloc] init];
74+
self.textInProgress = [[NSMutableString alloc] init];
7575

7676
// Initialize the stack with a fresh dictionary
77-
[dictionaryStack addObject:[NSMutableDictionary dictionary]];
77+
[self.dictionaryStack addObject:[NSMutableDictionary dictionary]];
7878

7979
// Parse the XML
8080
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
@@ -89,7 +89,7 @@ - (NSDictionary *)objectWithData:(NSData *)data options:(XMLReaderOptions)option
8989
// Return the stack's root dictionary on success
9090
if (success)
9191
{
92-
NSDictionary *resultDict = [dictionaryStack objectAtIndex:0];
92+
NSDictionary *resultDict = [self.dictionaryStack objectAtIndex:0];
9393
return resultDict;
9494
}
9595

@@ -102,7 +102,7 @@ - (NSDictionary *)objectWithData:(NSData *)data options:(XMLReaderOptions)option
102102
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
103103
{
104104
// Get the dictionary for the current level in the stack
105-
NSMutableDictionary *parentDict = [dictionaryStack lastObject];
105+
NSMutableDictionary *parentDict = [self.dictionaryStack lastObject];
106106

107107
// Create the child dictionary for the new element, and initilaize it with the attributes
108108
NSMutableDictionary *childDict = [NSMutableDictionary dictionary];
@@ -138,40 +138,39 @@ - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName nam
138138
}
139139

140140
// Update the stack
141-
[dictionaryStack addObject:childDict];
141+
[self.dictionaryStack addObject:childDict];
142142
}
143143

144144
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
145145
{
146146
// Update the parent dict with text info
147-
NSMutableDictionary *dictInProgress = [dictionaryStack lastObject];
147+
NSMutableDictionary *dictInProgress = [self.dictionaryStack lastObject];
148148

149149
// Set the text property
150-
if ([textInProgress length] > 0)
150+
if ([self.textInProgress length] > 0)
151151
{
152152
// trim after concatenating
153-
NSString *trimmedString = [textInProgress stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
153+
NSString *trimmedString = [self.textInProgress stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
154154
[dictInProgress setObject:[trimmedString mutableCopy] forKey:kXMLReaderTextNodeKey];
155155

156156
// Reset the text
157-
158-
textInProgress = [[NSMutableString alloc] init];
157+
self.textInProgress = [[NSMutableString alloc] init];
159158
}
160159

161160
// Pop the current dict
162-
[dictionaryStack removeLastObject];
161+
[self.dictionaryStack removeLastObject];
163162
}
164163

165164
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
166165
{
167166
// Build the text value
168-
[textInProgress appendString:string];
167+
[self.textInProgress appendString:string];
169168
}
170169

171170
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
172171
{
173172
// Set the error pointer to the parser's error object
174-
errorPointer = parseError;
173+
self.errorPointer = parseError;
175174
}
176175

177176
@end

0 commit comments

Comments
 (0)