Reputation: 3113
update 0
Do you mean to change all of the deals
to _deals
and all the iboards
to _iboards
and add the following method and then call it at the end of the processPbn
method? If so, what does the call look like?
- (id)initWithName:(NSInteger )_iboard deals:(NSArray *)_deals
{
self = [super init];
if (self) {
iboard = _iboard;
deals = _deals;
return self;
}
return nil;
}
update 0
I want to make the 2 variables deals
and iboards
, which are computed in BSViewcontroller
, available for use in BSdealViewController
. I am getting the following two Semantic Issues in the code at the end (the last 3 lines) of BSViewController.m .
"Local declaration of 'deals' hides instance variable"
"Local declaration of 'iboards' hides instance variable"
BSViewController.h
#import <UIKit/UIKit.h>
@interface BSViewController : UIViewController <....>
{
NSInteger iboard;
NSArray *deals;
}
@property (nonatomic) NSInteger iboard;
@property (nonatomic, strong) NSArray *deals;
- (void) processPbn;
@end
BSViewController.m
#import "BSViewController.h"
@interface BSViewController ()
@end
@implementation BSViewController
@synthesize iboard, deals;
- (void) processPbn
{
NSURLRequest *theRequest = [NSURLRequest .....];
[NSURLConnection sendAsynchronousRequest:theRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *connection, NSData *data, NSError *error)
{
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *sp = @" ";
NSArray*deals=@[[@[sp, sp, sp, sp]mutableCopy],[@[sp, sp, sp, sp]mutableCopy],[@[sp, sp, sp, sp]mutableCopy],[@[sp, sp, sp, sp]mutableCopy],[@[sp, sp, sp, sp]mutableCopy],[@[sp, sp, sp, sp]mutableCopy]];
NSString *toMatch = @"...";
int iboard = 0;
NSRegularExpression *regex = [....];
NSUInteger numberOfMatches = [....];
for (NSTextCheckingResult* board in [.....])
{
for (NSUInteger irange = 1; irange < board.numberOfRanges; ++irange)
{
NSRange matchedRange = [board rangeAtIndex: irange];
NSString* tstring = [string substringWithRange: matchedRange];
for (NSUInteger ix = 0; ix < tstring.length; ++ix)
{
NSRange cardInSuit = NSMakeRange(ix, 1);
int seat = (irange-1)/4 ;
int suit = (irange-1)%4 ;
NSString* replace= [deals[iboard][suit] ....];
[deals[iboard] replaceObjectAtIndex: suit withObject: replace];
}
}
++iboard;
}
}];
}
@end
(As a result of the above?) I am also getting the error Use of undeclared identifier 'iboard'
in the NSLog instruction below.
BSdealViewController.m
#import "BSdealViewController.h"
#import "BSViewController.h"
@interface BSdealViewController ()
@end
- (void)viewDidLoad
{
NSLog(@"iboard : %@", iboard);
}
Upvotes: 1
Views: 1769
Reputation: 52538
Here's the convention used by most experienced developers that you should follow:
Use properties when possible, for example a property "iboard" and a property "deals". Use instance variables with a leading underscore, like "_iboard" and "_deals".
Do NOT use a leading underscore anywhere else.
This way anyone reading your source code can spot the use of instance variables from a mile away, and you cannot accidentally use an instance variable when you meant to use a property. Your init method should be
- (id)initWithIBoard:(NSInteger )iboard deals:(NSArray *)deals
{
if ((self = [super init]) != nil)
{
_iboard = iboard;
_deals = deals;
}
return self;
}
Upvotes: 0
Reputation: 46533
"Local declaration of 'deals' hides instance variable" "Local declaration of 'iboard' hides instance variable"
You have variable named deals
in your method that is a collision with ivar having same name.
NSString *toMatch = @"...";
int iboard = 0; ^^^^^^ NSRegularExpression *regex = [....];
Also,
NSString *sp = @" ";
NSArray*deals=@[[@[sp, sp, sp, sp]mutableCopy],[@[sp, sp, sp, sp]mutableCopy],[@[sp, sp, sp, sp]mutableCopy],[@[sp, sp, sp, sp]mutableCopy],[@[sp, sp, sp, sp]mutableCopy],[@[sp, sp, sp, sp]mutableCopy]];
^^^^^
Change the variable in the method name to aDeals
and aIboards
or something that is different from ivars.
Upvotes: 3