Use Of Undeclared Identifier in my function - ios

I'm having a use of undeclared identifier even though that I declared it in the .h and synthesize in the .m.
I had another problem before, but I posted a question in stack overflow and they said that I shouldn't extern them and when I extered them the code gave me an error "ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)" and know I didn't and it's giving me "Use Of Undeclared Identifier" as you can see
.h
#import <UIKit/UIKit.h>
BOOL OFrameIsHidden, XFrameIsHidden;
NSString *topOne, *topTwo, *topThree;
NSString *midOne, *midTwo, *midThree;
NSString *botOne, *botTwo, *botThree;
void hideAll(void);
#interface ViewController : UIViewController
void hideAll(void);
#property (weak, nonatomic) IBOutlet UIImageView *XFrame;
#property (weak, nonatomic) IBOutlet UIImageView *OFrame;
#property (weak, nonatomic) IBOutlet UIImageView *frame;
#property (weak, nonatomic) IBOutlet UILabel *X;
#property (weak, nonatomic) IBOutlet UILabel *O;
#property (weak, nonatomic) IBOutlet UILabel *WhoWon;
#property (weak, nonatomic) IBOutlet UIButton *oneOne;
#property (weak, nonatomic) IBOutlet UIButton *oneTwo;
#property (weak, nonatomic) IBOutlet UIButton *oneThree;
#property (weak, nonatomic) IBOutlet UIButton *twoOne;
#property (weak, nonatomic) IBOutlet UIButton *twoTwo;
#property (weak, nonatomic) IBOutlet UIButton *twoThree;
#property (weak, nonatomic) IBOutlet UIButton *threeOne;
#property (weak, nonatomic) IBOutlet UIButton *threeTwo;
#property (weak, nonatomic) IBOutlet UIButton *threeThree;
#end
.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize XFrame, OFrame, frame, X, O, WhoWon;
#synthesize oneOne, oneTwo, oneThree;
#synthesize twoOne, twoTwo, twoThree;
#synthesize threeOne, threeTwo, threeThree;
void hideAll(void){
[OFrame setHidden:YES];
[XFrame setHidden:YES];
[frame setHidden:YES];
[X setHidden:YES];
[O setHidden:YES];
[oneOne setHidden:YES];
[oneTwo setHidden:YES];
[oneThree setHidden:YES];
[oneOne setHidden:YES];
[twoTwo setHidden:YES];
[twoThree setHidden:YES];
[threeOne setHidden:YES];
[threeTwo setHidden:YES];
[threeThree setHidden:YES];
}
For your information there is some more code for the IBAcions, but I don't want to make this long.

Don't mix functions and methods like this. It doesn't really help you and all you have done is create visibility issues.
Methods work by passing a hidden parameter which gives access to self. All of your #property definitions are instance variables, so you need access to self to get to them. Functions, like your hideAll, don't have this access so they can't get to the instance variables (they don't know what an instance is).
You generally also don't want variables defined outside the class definition.
Bring your variables into the class or move them to another more appropriate class and use methods for your code, not functions.

Related

How do I fix the error "Expected Expression"

So I was making an app on Xcode ( Objective C) and I really am not able to find a way to fix it
Can somebody please help me with this?
#import "ViewController.h"
#import "DistanceGetter/DGDistanceRequest.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UITextField *startLocation;
#property (nonatomic) DGDistanceRequest *req;
#property (weak, nonatomic) IBOutlet UITextField *endLocationA;
#property (strong, nonatomic) IBOutlet UIView *distanceA;
#property (weak, nonatomic) IBOutlet UITextField *endLocationB;
#property (weak, nonatomic) IBOutlet UILabel *distanceB;
#property (weak, nonatomic) IBOutlet UITextField *endLocationC;
#property (weak, nonatomic) IBOutlet UILabel *distanceC;
#property (weak, nonatomic) IBOutlet UIButton *calculateButton;
#end
#implementation ViewController
- (IBAction)calculateButtonTapped:(id)sender {
self.calculateButton.enabled=NO;
self.req = [DGDistanceRequest alloc];
NSString *start = self.startLocation.text;
NSString *destA = self.endLocationA.text;
NSString *destB = self.endLocationA.text;
NSString *destC = self.endLocationA.text;
NSArray *dests = #[destA,destB,destC];
self.req = [self.req initWithLocationDescriptions:dests
sourceDescription:start];
self.req.callback= void(ˆNSArray *responses)
self.distanceC.text=#"callback";
self.calculateButton.enabled = YES;
self.req=nil;
When I make it ˆvoid(NSArray.....) it gives even more errors
You have a typo :
void(^... should be ^void(... - the error is somewhat misleading, and it seems strange than Xcode didn’t suggest a „Fix-it”.
Anyway, I recommend http://goshdarnblocksyntax.com/ to remind yourself with block syntax.

Array of UIButtons return error

I have an array of UIButton objects (I have 5 buttons so I wanted to store them in an array for easy processing). But Array give me error
"Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSArray0 addObject:]:
unrecognized selector sent to instance"
#property (weak, nonatomic) IBOutlet UIButton *starOne;
#property (weak, nonatomic) IBOutlet UIButton *starTwo;
#property (weak, nonatomic) IBOutlet UIButton *starThree;
#property (weak, nonatomic) IBOutlet UIButton *starFour;
#property (weak, nonatomic) IBOutlet UIButton *starFive;
#property (nonatomic, copy) NSMutableArray *_starButtons;
I have below code in viewDidLoad method
- (void)viewDidLoad {
self._starButtons=[[NSMutableArray alloc]init];
[self._starButtons addObject:self.starOne];
[self._starButtons addObject:self.starTwo];
[self._starButtons addObject:self.starThree];
[self._starButtons addObject:self.starFour];
[self._starButtons addObject:self.starFive];
NSLog(#"%#",self._starButtons);
}
Please help me where i am going wrong.
First remove copy from declaration of array property, make it strong.
Second thing as you have said in comment that you have programmatically created buttons then you not need IBOutlets. So, remove IBOutlets from all properties of button.
Your declaration should like,
#property (weak, nonatomic) UIButton *starOne;
#property (weak, nonatomic) UIButton *starTwo;
#property (weak, nonatomic) UIButton *starThree;
#property (weak, nonatomic) UIButton *starFour;
#property (weak, nonatomic) UIButton *starFive;
#property (nonatomic, strong) NSMutableArray *_starButtons;
Try this:
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UIButton *one;
#property (weak, nonatomic) IBOutlet UIButton *two;
#property (weak, nonatomic) IBOutlet UIButton *three;
#end
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray *buttonArray = [[NSMutableArray alloc] initWithObjects:one,two,three,nil];
NSLog(#"%#",buttonArray);
}
If you're using Storyboard or Nib file then:
Another approach is to connect the UIButtons' to an NSArray of IBOutletCollection in Interface Builder, instead of adding manually each button to an NSMutableArray. Something like this for all UIButtons'.
#property (nonatomic, retain) IBOutletCollection(UIButton) NSArray *buttonsArray;
Just one change in code.
Replace this line:
#property NSMutableArray *_starButtons;

-[MyDictationController respondsToSelector:] message sent ot deallocated instance

My app crashes with this stack trace:
[DictationDetailsController respondsToSelector:]: message sent to deallocated instance
I tracked that on instruments trying to see the relevant code causing the crash:
here is the relevant code for MyDictationController in the didSelectRowAtIndexPath: delegate method:
- (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath {
DictationDetailsController *controller = GET_CONTROLLER_WITH_CLASS([DictationDetailsController class]);
controller.dictation = [unSubmittedDictations objectAtIndex:indexPath.row];
controller.isEditMode = YES;
controller.selectedDate = _selectedDate;
controller.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:controller animated:YES];
}
#property (copy ,nonatomic) Dictation *dictation;
Also i have used #synthesize. Help me out in this issue, to get which deallocated method is being called.?
Here's my DictationDetailsController interface:
#interface DictationDetailsController : BaseController
#property (copy ,nonatomic) Dictation *dictation;
#property (nonatomic) BOOL isEditMode;
#property (nonatomic) NSDate *selectedDate;
#property (weak, nonatomic) IBOutlet UILabel *navigationTitleLabel;
#property (weak, nonatomic) IBOutlet UITextField *patientNameTextField;
#property (weak, nonatomic) IBOutlet UITextField *accountIDTextField;
#property (weak, nonatomic) IBOutlet UITextField *workTypeTextField;
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *deleteButtonWidth;
#property (weak, nonatomic) IBOutlet UIView *tutorialView;
#property (weak, nonatomic) IBOutlet UIView *audioContainer;
#property (weak, nonatomic) IBOutlet UISlider *audioSlider;
#property (weak, nonatomic) IBOutlet UILabel *durationLabel;
#property (weak, nonatomic) IBOutlet UILabel *noRecordingLabel;
#property (weak, nonatomic) IBOutlet UIButton *playPauseButton;
#end
And in dealloc method:
- (void)dealloc {
[player pause];
player = nil;
self.dictation = nil;
}
My guess is the issue is somewhere inside GET_CONTROLLER_WITH_CLASS method. Pop a breakpoint on that line and step over it. It's possibly producing a released instance of the class. That being the case, the crash would occur on the line immediately following the call to that method when it tries to access the dictation property.

Access Variable Dynamically

I have many buttons named like this:
#property (weak, nonatomic) IBOutlet UIButton *Round1Num1;
#property (weak, nonatomic) IBOutlet UIButton *Round1Num2;
#property (weak, nonatomic) IBOutlet UIButton *Round1Num3;
#property (weak, nonatomic) IBOutlet UIButton *Round1Num4;
#property (weak, nonatomic) IBOutlet UIButton *Round2Num1;
#property (weak, nonatomic) IBOutlet UIButton *Round2Num2;
#property (weak, nonatomic) IBOutlet UIButton *Round2Num3;
#property (weak, nonatomic) IBOutlet UIButton *Round2Num4;
and so on.
I was wondering if I could access them dynamically using stringWithFormat or a similar method.
Example (Sorry if the code is wrong!):
Instead of self.Round1Num1 I could call self.[NSString stringWithFormat:#"Round%dNum%d", 1, 1]
You could use -performSelector::
NSString *round2Num1ButtonAccessorSelectorStr = [NSString stringWithFormat:#"Round%dNum%d", 2, 1];
SEL selector = NSSelectorFromString(round2Num1ButtonAccessorSelectorStr);
if ([self respondsToSelector:selector])
UIButton *round2Num1Button = [self performSelector:selector];
For context, [self performSelector:#selector(someSelector)] is essentially the equivalent to self.someSelector (in the case of a property accessor) which resolves to [self someSelector]. All cases actually call the same runtime function, objc_msgSend(self, someSelector).
Specifically in this context, we're creating a local variable that points to the same reference concealed by the respective IBOutlet property on the VC instance. If the property doesn't exist, then neither will the selector (most likely) so you need to safeguard from an unrecognized selector exception via -respondsToSelector:.

How to fix the warning of "Autosynthesized property 'myVar' will use synthesized instance variable '_myVar', not existing instance variable 'myVar' "?

I declare my .h file like this:
#import <UIKit/UIKit.h>
#interface NavigationTripViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>{
NSArray *questionTitleTrip;
NSArray *questionDescTrip;
NSMutableArray *answerTrip;
NSMutableArray *pickerChoices;
int questionInt;
int totalInt;
IBOutlet UILabel *questionNum;
IBOutlet UILabel *questionTotalNum;
IBOutlet UILabel *recordType;
IBOutlet UITextView *questionDes;
IBOutlet UIView *answerView;
IBOutlet UIButton *preButton;
IBOutlet UIButton *nextButton;
UITextField *text;
UIPickerView *picker;
}
#property (retain, nonatomic) NSArray *questionTitleTrip;
#property (retain, nonatomic) NSArray *questionDescTrip;
#property (retain, nonatomic) NSMutableArray *answerTrip;
#property (retain, nonatomic) NSMutableArray *pickerChoices;
#property (retain, nonatomic) IBOutlet UILabel *questionNum;
#property (retain, nonatomic) IBOutlet UILabel *questionTotalNum;
#property (retain, nonatomic) IBOutlet UILabel *recordType;
#property (retain, nonatomic) IBOutlet UITextView *questionDes;
#property (retain, nonatomic) IBOutlet UIView *answerView;
#property (retain, nonatomic) IBOutlet UIButton *preButton;
#property (retain, nonatomic) IBOutlet UIButton *nextButton;
#property (retain, nonatomic) UITextField *text;
#property (retain, nonatomic) UIPickerView *picker;
-(IBAction)clickPre;
-(IBAction)clickNext;
#end
And my .m file here like this:
#import "NavigationTripViewController.h"
#import <QuartzCore/QuartzCore.h>
#interface NavigationTripViewController ()
#end
#implementation NavigationTripViewController
#synthesize questionTitleTrip,questionDescTrip,answerTripl,pickerChoices,questionNum,questionTotalNum,recordType,questionDes,answerView,preButton,nextButton,text,picker;
All my variables in the #synthesize receive the warnings:
Autosynthesized property 'myVar' will use synthesized instance variable '_myVar', not existing instance variable 'myVar'
Also, the variables and class names used in viewDidLoad don't display in colors, just show in black color. In other view controllers, there are no warnings like this. How to fix these problems?
Edit:
Basically for all intents and purposes you should be building on a new enough XCode to use the new behavior, in that solution you typically will just remove the ivar from the #interface block in the .h file... If for some reason you do need to access an ivar directly you can now declare it in the #implementation block... and use #synthesize var or #synthesize var=_var
OGPost:
to make that go away you can go all new school and drop the iVar, or you can go all old school and add an #synthesize someIvar in your #implementation block.

Resources