Skip to content

Commit

Permalink
Move properties to be nonatomic, and remove explicit @synthesize decl…
Browse files Browse the repository at this point in the history
…arations
  • Loading branch information
stig committed Nov 10, 2013
1 parent b41acb1 commit 641f506
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
NSWindow *window;
}

@property (assign) IBOutlet NSWindow *window;
@property (nonatomic, weak) IBOutlet NSWindow *window;

@end
4 changes: 2 additions & 2 deletions Examples/TweetStream/TweetStream/TweetStreamAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, weak) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet TweetStreamViewController *viewController;
@property (nonatomic, weak) IBOutlet TweetStreamViewController *viewController;

@end
9 changes: 2 additions & 7 deletions Examples/TweetStream/TweetStream/TweetStreamAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@

@implementation TweetStreamAppDelegate


@synthesize window=_window;

@synthesize viewController=_viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.

self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
Expand All @@ -37,7 +32,7 @@ - (void)applicationWillResignActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
{
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/objc/SBJsonParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
malicious and the parser returns nil, signalling an error. ("Nested too deep".) You can
turn off this security feature by setting the maxDepth value to 0.
*/
@property NSUInteger maxDepth;
@property(nonatomic) NSUInteger maxDepth;

/**
Description of parse error
Expand All @@ -57,7 +57,7 @@
@return A string describing the error encountered, or nil if no error occured.
*/
@property(copy) NSString *error;
@property(nonatomic, copy) NSString *error;

/**
Return the object represented by the given NSData object.
Expand Down
8 changes: 4 additions & 4 deletions src/main/objc/SBJsonStreamParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ typedef enum {
type if they fit, else a `double` is used. All real & exponential numbers
are represented using a `double`. Previous versions of this library used
an NSDecimalNumber in some cases, but this is no longer the case.
See also SBJsonStreamParserAdapter for more information.
*/
Expand All @@ -134,7 +134,7 @@ typedef enum {
Usually this should be an instance of SBJsonStreamParserAdapter, but you can
substitute your own implementation of the SBJsonStreamParserDelegate protocol if you need to.
*/
@property (weak) id<SBJsonStreamParserDelegate> delegate;
@property (nonatomic, weak) id<SBJsonStreamParserDelegate> delegate;

/**
The max parse depth
Expand All @@ -143,10 +143,10 @@ typedef enum {
Defaults to 32.
*/
@property NSUInteger maxDepth;
@property(nonatomic) NSUInteger maxDepth;

/// Holds the error after SBJsonStreamParserError was returned
@property (copy) NSString *error;
@property (nonatomic, copy) NSString *error;

/**
Parse some JSON
Expand Down
102 changes: 48 additions & 54 deletions src/main/objc/SBJsonStreamParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,14 @@ @implementation SBJsonStreamParser {
SBJsonStreamTokeniser *tokeniser;
}

@synthesize error;
@synthesize delegate;
@synthesize maxDepth;
@synthesize state;
@synthesize stateStack;

#pragma mark Housekeeping

- (id)init {
self = [super init];
if (self) {
maxDepth = 32u;
stateStack = [[NSMutableArray alloc] initWithCapacity:maxDepth];
state = [SBJsonStreamParserStateStart sharedInstance];
_maxDepth = 32u;
_stateStack = [[NSMutableArray alloc] initWithCapacity:_maxDepth];
_state = [SBJsonStreamParserStateStart sharedInstance];
tokeniser = [[SBJsonStreamTokeniser alloc] init];
}
return self;
Expand Down Expand Up @@ -118,53 +112,53 @@ - (NSString*)tokenName:(sbjson_token_t)token {
return @"<aaiiie!>";
}

- (void)maxDepthError {
self.error = [NSString stringWithFormat:@"Input depth exceeds max depth of %lu", (unsigned long)maxDepth];
self.state = [SBJsonStreamParserStateError sharedInstance];
- (void)_maxDepthError {
self.error = [NSString stringWithFormat:@"Input depth exceeds max depth of %lu", (unsigned long)_maxDepth];
_state = [SBJsonStreamParserStateError sharedInstance];
}

- (void)handleObjectStart {
if (stateStack.count >= maxDepth) {
[self maxDepthError];
if (_stateStack.count >= _maxDepth) {
[self _maxDepthError];
return;
}

[delegate parserFoundObjectStart:self];
[stateStack addObject:state];
self.state = [SBJsonStreamParserStateObjectStart sharedInstance];
[_delegate parserFoundObjectStart:self];
[_stateStack addObject:_state];
_state = [SBJsonStreamParserStateObjectStart sharedInstance];
}

- (void)handleObjectEnd: (sbjson_token_t) tok {
self.state = [stateStack lastObject];
[stateStack removeLastObject];
[state parser:self shouldTransitionTo:tok];
[delegate parserFoundObjectEnd:self];
_state = [_stateStack lastObject];
[_stateStack removeLastObject];
[_state parser:self shouldTransitionTo:tok];
[_delegate parserFoundObjectEnd:self];
}

- (void)handleArrayStart {
if (stateStack.count >= maxDepth) {
[self maxDepthError];
if (_stateStack.count >= _maxDepth) {
[self _maxDepthError];
return;
}

[delegate parserFoundArrayStart:self];
[stateStack addObject:state];
self.state = [SBJsonStreamParserStateArrayStart sharedInstance];
[_delegate parserFoundArrayStart:self];
[_stateStack addObject:_state];
_state = [SBJsonStreamParserStateArrayStart sharedInstance];
}

- (void)handleArrayEnd: (sbjson_token_t) tok {
self.state = [stateStack lastObject];
[stateStack removeLastObject];
[state parser:self shouldTransitionTo:tok];
[delegate parserFoundArrayEnd:self];
_state = [_stateStack lastObject];
[_stateStack removeLastObject];
[_state parser:self shouldTransitionTo:tok];
[_delegate parserFoundArrayEnd:self];
}

- (void) handleTokenNotExpectedHere: (sbjson_token_t) tok {
NSString *tokenName = [self tokenName:tok];
NSString *stateName = [state name];
NSString *stateName = [_state name];

self.error = [NSString stringWithFormat:@"Token '%@' not expected %@", tokenName, stateName];
self.state = [SBJsonStreamParserStateError sharedInstance];
_state = [SBJsonStreamParserStateError sharedInstance];
}

- (SBJsonStreamParserStatus)parse:(NSData *)data_ {
Expand All @@ -173,7 +167,7 @@ - (SBJsonStreamParserStatus)parse:(NSData *)data_ {

for (;;) {

if ([state isError])
if ([_state isError])
return SBJsonStreamParserError;

char *token;
Expand All @@ -182,18 +176,18 @@ - (SBJsonStreamParserStatus)parse:(NSData *)data_ {

switch (tok) {
case sbjson_token_eof:
return [state parserShouldReturn:self];
return [_state parserShouldReturn:self];
break;

case sbjson_token_error:
self.state = [SBJsonStreamParserStateError sharedInstance];
_state = [SBJsonStreamParserStateError sharedInstance];
self.error = tokeniser.error;
return SBJsonStreamParserError;
break;

default:

if (![state parser:self shouldAcceptToken:tok]) {
if (![_state parser:self shouldAcceptToken:tok]) {
[self handleTokenNotExpectedHere: tok];
return SBJsonStreamParserError;
}
Expand All @@ -217,57 +211,57 @@ - (SBJsonStreamParserStatus)parse:(NSData *)data_ {

case sbjson_token_value_sep:
case sbjson_token_entry_sep:
[state parser:self shouldTransitionTo:tok];
[_state parser:self shouldTransitionTo:tok];
break;

case sbjson_token_bool:
[delegate parser:self foundBoolean:token[0] == 't'];
[state parser:self shouldTransitionTo:tok];
[_delegate parser:self foundBoolean:token[0] == 't'];
[_state parser:self shouldTransitionTo:tok];
break;


case sbjson_token_null:
[delegate parserFoundNull:self];
[state parser:self shouldTransitionTo:tok];
[_delegate parserFoundNull:self];
[_state parser:self shouldTransitionTo:tok];
break;

case sbjson_token_integer: {
const int UNSIGNED_LONG_LONG_MAX_DIGITS = 20;
if (token_len <= UNSIGNED_LONG_LONG_MAX_DIGITS) {
if (*token == '-')
[delegate parser:self foundNumber: @(strtoll(token, NULL, 10))];
[_delegate parser:self foundNumber: @(strtoll(token, NULL, 10))];
else
[delegate parser:self foundNumber: @(strtoull(token, NULL, 10))];
[_delegate parser:self foundNumber: @(strtoull(token, NULL, 10))];

[state parser:self shouldTransitionTo:tok];
[_state parser:self shouldTransitionTo:tok];
break;
}
}
// FALLTHROUGH

case sbjson_token_real: {
[delegate parser:self foundNumber: @(strtod(token, NULL))];
[state parser:self shouldTransitionTo:tok];
[_delegate parser:self foundNumber: @(strtod(token, NULL))];
[_state parser:self shouldTransitionTo:tok];
break;
}

case sbjson_token_string: {
NSString *string = [[NSString alloc] initWithBytes:token length:token_len encoding:NSUTF8StringEncoding];
if ([state needKey])
[delegate parser:self foundObjectKey:string];
if ([_state needKey])
[_delegate parser:self foundObjectKey:string];
else
[delegate parser:self foundString:string];
[state parser:self shouldTransitionTo:tok];
[_delegate parser:self foundString:string];
[_state parser:self shouldTransitionTo:tok];
break;
}

case sbjson_token_encoded: {
NSString *string = [self decodeStringToken:token length:token_len];
if ([state needKey])
[delegate parser:self foundObjectKey:string];
if ([_state needKey])
[_delegate parser:self foundObjectKey:string];
else
[delegate parser:self foundString:string];
[state parser:self shouldTransitionTo:tok];
[_delegate parser:self foundString:string];
[_state parser:self shouldTransitionTo:tok];
break;
}

Expand Down
22 changes: 11 additions & 11 deletions src/main/objc/SBJsonStreamParserAdapter.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/*
Copyright (c) 2010, Stig Brautaset.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
Neither the name of the the author nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
Expand Down Expand Up @@ -110,7 +110,7 @@ typedef enum {
NSMutableArray *stack;
NSMutableArray *path;
id (^processBlock)(id, NSString*);

SBJsonStreamParserAdapterType currentType;
}

Expand All @@ -129,24 +129,24 @@ typedef enum {
If you set this to YES the -parser:found: delegate method will be called once for each document in your input.
*/
@property BOOL supportManyDocuments;
@property(nonatomic) BOOL supportManyDocuments;


/**
Support partial documents.
This is useful for parsing huge JSON documents, or documents coming in over a very slow link.
If you set this to true the outer array will be ignored and -parser:found: is called once
for each item in it.
*/
@property BOOL supportPartialDocuments;
@property(nonatomic) BOOL supportPartialDocuments;

/**
Your delegate object
Set this to the object you want to receive the SBJsonStreamParserAdapterDelegate messages.
*/
@property (weak) id<SBJsonStreamParserAdapterDelegate> delegate;
@property (nonatomic, weak) id<SBJsonStreamParserAdapterDelegate> delegate;

@end
4 changes: 1 addition & 3 deletions src/main/objc/SBJsonStreamParserAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ - (void)parser:(SBJsonStreamParser*)parser found:(id)obj;

@implementation SBJsonStreamParserAdapter

@synthesize delegate;

#pragma mark Housekeeping

- (id)init {
Expand Down Expand Up @@ -117,7 +115,7 @@ - (void)parser:(SBJsonStreamParser*)parser found:(id)obj isValue:(BOOL)isValue {
break;

case SBJsonStreamParserAdapterNone:
[delegate parser:parser found:obj];
[_delegate parser:parser found:obj];
break;

default:
Expand Down
Loading

0 comments on commit 641f506

Please sign in to comment.