property not found on object of type error but property is there - objective-c

So I'm trying to access the property isPortClosed(BOOL) in SerialPortController and its giving me an error, I'm kinda new to objective-c. I feel like this should work as I've got a reference to the class with *port. Here is a link to the project.
Error messages: ~/GroundStation/GroundStation/ViewController.m:16:22: Property 'isPortClosed' not found on object of type 'SerialPortController *'
#import <Cocoa/Cocoa.h>
#import "SceneView.h"
#import "SerialPortController.h"
#interface ViewController : NSViewController
#property (strong) IBOutlet SerialPortController *port;
#property (weak) IBOutlet SceneView *accelSceneView;
#end
#import "ViewController.h"
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
while(!self.port.isPortClosed) {
}
}
- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];
// Update the view, if already loaded.
}
#end
SerialPortController.h class
#import <Foundation/Foundation.h>
#import <ORSSerial/ORSSerial.h>
#interface SerialPortController : NSObject <ORSSerialPortDelegate>
#property (nonatomic, strong) ORSSerialPort *serial;
#property (nonatomic, strong) ORSSerialPortManager *serialPortManager;
#property (nonatomic) NSInteger xAngle;
#property (nonatomic) NSInteger yAngle;
#property (nonatomic) NSInteger zAngle;
#property (nonatomic) NSString *stringBuffer;
#property (nonatomic) BOOL isPortClosed;
#end

From the downloaded project I see that you have two SerialPortController class definitions (one at the root directory, and one in /GroundStation/), and the latter doesn't have any public properties. You should have only one SerialPortController class definition linked in your project (the one with the public properties).

Related

How to silent warning incompatible property type

I am using RTSPagedView from github in my project. Which gives me this warning
Property type 'id<RTSPagedViewDelegate>' is incompatible with type 'id<UIScrollViewDelegate>' unherited from 'UIScrollView'
in
#property (nonatomic, assign) IBOutlet id <RTSPagedViewDelegate> delegate;
in RTSPagedView.h
App is working fine with this warning. Anyone came across this before or knows the solution please help.
Link for this is RTSPagedView
// RTSPagedView.h
// PagedView
// http://github.com/rplasman/RTSPagedView
#import <UIKit/UIKit.h>
#protocol RTSPagedViewDelegate;
#interface RTSPagedView : UIScrollView
#property (nonatomic, assign) IBOutlet id <RTSPagedViewDelegate> delegate;
#property (nonatomic, assign) NSUInteger currentPage;
#property (nonatomic, readonly) NSUInteger numberOfPages;
#property (nonatomic, assign) BOOL continuous;
- (void)resizeBounds:(CGRect)bounds;
- (UIView *)dequeueReusableViewWithTag:(NSInteger)tag;
- (UIView *)viewForPageAtIndex:(NSUInteger)index;
- (void)scrollToPageAtIndex:(NSUInteger)index animated:(BOOL)animated;
- (void)reloadData;
- (NSUInteger)indexForView:(UIView *)view;
#end
#protocol RTSPagedViewDelegate <UIScrollViewDelegate>
- (NSUInteger)numberOfPagesInPagedView:(RTSPagedView *)pagedView;
- (UIView *)pagedView:(RTSPagedView *)pagedView viewForPageAtIndex:(NSUInteger)index;
#optional
- (void)pagedView:(RTSPagedView *)pagedView didScrollToPageAtIndex:(NSUInteger)index;
- (void)pagedView:(RTSPagedView *)pagedView didRecycleView:(UIView *)view;
#end
Try it this way:
#property (nonatomic, assign) IBOutlet id <UIScrollViewDelegate, RTSPagedViewDelegate> delegate;
Works for me.
Issue occurred because
#property (nonatomic, assign) IBOutlet id <RTSPagedViewDelegate> delegate;
In this delagate is poniting towards UIScrollViewDelagate because RTSPagedView is inherited from UIScrollView.
Modify the complete delegate name with any other name like
#property (nonatomic, assign) IBOutlet id <RTSPagedViewDelegate> rtspDelegate;
It will remove the warning.
I think (I cannot be sure without more code) that you are haven't declared your delegate class as conforming to the RTSPagedViewDelegate protocol.
try this:
YourClass.h:
#interface YourClass : NSObject <UIScrollViewDelegate, RTSPagedViewDelegate>
...
#end
And now when you do:
rtsPageView.delegate = self;
The warning should be gone.
This could be complete rubbish, in which case I'll delete it.

Setting variables in a different class in Cocoa

I'm trying to learn how to set variables for different classes using one main data class.
Here's a diagram of of what I would like to do and the code from my project:
ClassA
#import <Foundation/Foundation.h>
#interface ClassA : NSObject {
NSString *stringA;
NSString *stringB;
}
#property (nonatomic, copy) NSString *stringA;
#property (nonatomic, copy) NSString *stringB;
#property (weak) IBOutlet NSTextField *textA;
#property (weak) IBOutlet NSTextField *textB;
- (IBAction)displayStrings:(id)sender;
#end
#import "ClassA.h"
#implementation ClassA
#synthesize stringA, stringB, textA, textB;
- (IBAction)displayStrings:(id)sender {
[textA setStringValue:stringA];
[textB setStringValue:stringB];
}
#end
Class X
#import <Foundation/Foundation.h>
#interface ClassX : NSObject {
NSMutableString *stringX;
}
- (void)theVariables:(id)sender;
#end
#import "ClassX.h"
#import "ClassA.h"
#implementation ClassX
- (void)awakeFromNib {
[self theVariables:self];
}
- (void)theVariables:(id)sender {
stringX = [[NSMutableString alloc] init];
ClassA *clssA = [[ClassA alloc] init];
[stringX setString:#"stringX for stringA"];
[clssA setStringA:stringX];
[stringX setString:#"stringX for stringB"];
[clssA setStringB:stringX];
}
#end
No errors show up in the code, but when I run the program I am receiving an error about "Invalid parameter not satisfying: aString". It looks like the setStringValue for the IBOutlet is not working. Any suggestions?
I'm not seeing the error you mention, but as far as I can tell from your code, the main problem is this line:
ClassA *clssA = [[ClassA alloc] init];
You must have an instance of ClassA in your xib, which is connected to text fields and a button. That object in the xib is a real object, and if you just create another instance of ClassA somewhere in your code, you have an entirely different object that has no connection to the one that's in your xib.
You need to make sure of/change two things. First, there needs to be an instance of ClassX in your xib. Second, ClassX needs an outlet to a ClassA instance:
#class ClassA; // Declare ClassA so you can use it below
#interface ClassX : NSObject
#property (weak) IBOutlet ClassA * theClassAInstance;
- (void)theVariables:(id)sender;
#end
Which should then be connected in the xib file. Then, in theVariables:, you just use that outlet instead of creating a new instance of ClassA: [[self theClassAInstance] setStringA:#"stringX for stringA"];
Three points of style:
First, you should be importing Cocoa.h: #import <Cocoa/Cocoa.h> instead of Foundation.h in any class that touches the GUI (ClassA in this case). That's where stuff like NSTextField is defined. It works anyways because Cocoa.h is imported via your .pch file, but it's best to be explicit.
Second, creating a mutable string and changing its value to two different literal strings doesn't make a whole lot of sense. Just use the literals directly: [clssA setStringA:#"stringX for stringA"];
Third, You don't need to declare the instance variables separately; #synthesize creates them for you, and it is now the recommended practice to not declare them:
#interface ClassA : NSObject
#property (nonatomic, copy) NSString *stringA;
#property (nonatomic, copy) NSString *stringB;
#property (weak) IBOutlet NSTextField *textA;
#property (weak) IBOutlet NSTextField *textB;
- (IBAction)displayStrings:(id)sender;
#end
Last (four points!), you should really be accessing the values of stringA and stringB in ClassA via the property: [textA setStringValue:[self stringA]];

create control with properties within it

I have control something like this
#import <Foundation/Foundation.h>
#import "AQLevelMeter.h"
#import "AQPlayer.h"
#import "AQRecorder.h"
#interface SpeakHereController : NSObject {
IBOutlet UIBarButtonItem* btn_record;
IBOutlet UIBarButtonItem* btn_play;
IBOutlet UILabel* fileDescription;
IBOutlet AQLevelMeter* lvlMeter_in;
AQPlayer* player;
AQRecorder* recorder;
BOOL playbackWasInterrupted;
BOOL playbackWasPaused;
}
#property (nonatomic, retain) UIBarButtonItem *btn_record;
#property (nonatomic, retain) UIBarButtonItem *btn_play;
#property (nonatomic, retain) UILabel *fileDescription;
#property (nonatomic, retain) AQLevelMeter *lvlMeter_in;
#property (readonly) AQPlayer *player;
#property (readonly) AQRecorder *recorder;
#property BOOL playbackWasInterrupted;
#property BOOL isReport;
#property CFStringRef recordFilePath;
- (IBAction)record: (id) sender;
- (IBAction)play: (id) sender;
-(void) InitializeThePlayer;
#end
as we can see I added many properties like
#property BOOL isReport;
#property CFStringRef recordFilePath;
then I created uiview contains this control
#import <UIKit/UIKit.h>
#class SpeakHereController;
#interface SpeakHereViewController : UIViewController {
IBOutlet SpeakHereController *controller;
}
Now I want to access the properties of the control object so I say
- (void)viewWillAppear:(BOOL)animated {
[self ReportDirectory];
[controller setIsReport:self.iSReport ];
//controller.isReport = self.iSReport ;
[controller setRecordFilePath:(CFStringRef) self.DICOMpath];
//controller.recordFilePath = ;
}
the problem is that at the lines
[controller setIsReport:self.iSReport ];
[controller setRecordFilePath:(CFStringRef) self.DICOMpath];
there is warning say that
warning: no '-setIsReport:' method found
I made
#synthesize isReport;
#synthesize recordFilePath;
also if I replaced #class SpeakHereController; by #import "SpeakHereController.h" it raise a lot of errors , U can download the sample code from apple
and if I said controller.isReport = self.iSReport ; it raise error request for member 'isReport' in something not a structure or union
My question is how to call the properties in this control , am I missing something
Best regards
I tried
At the top of SpeakHereViewController.m you will need
import "SpeakHereController.h"
Otherwise when SpeakHereViewController.m is compiled, it is completely unaware of what methods and properties your SpeakHereController class has
It should run fine even with the warning because the property does exist. However, I agree with you that the warning needs to be dealt with.
You should synthesize those properties in .m file.
The syntax is like:
#synthesize isReport, recordFilePath;

'Existing ivar 'delegate' for unsafe_unretained property 'delegate' must be __unsafe_unretained

I'm getting the error above, but unsure how to go about fixing it. This is my code:
.h:
#import <UIKit/UIKit.h>
#protocol ColorLineDelegate <NSObject>
-(void)valueWasChangedToHue:(float)hue;
#end
#interface ColorLine : UIButton {
id <ColorLineDelegate> delegate;
}
#property (nonatomic, assign) id <ColorLineDelegate> delegate;
#end
.m:
#import "ColorLine.h"
#implementation ColorLine
#synthesize delegate;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
#end
The error occurs in the synthesize line. I can't find a problem though.
Use this syntax:
#interface SomeClass : NSObject {
id <SomeClassDelegate> __unsafe_unretained delegate;
}
#property (unsafe_unretained) id <SomeClassDelegate> delegate;
Looks like your project might be using ARC then properties should be declared this way:
#import <UIKit/UIKit.h>
#protocol ColorLineDelegate <NSObject>
-(void)valueWasChangedToHue:(float)hue;
#end
#interface ColorLine : UIButton
#property (nonatomic, weak) id <ColorLineDelegate> delegate;
#end
I had the same problem when I used old example code which did not feature ARC in my ARC project. It seems that you do not need to put the variable declarations into the interface definition any more. So your code should work like this:
h:
#import <UIKit/UIKit.h>
#protocol ColorLineDelegate <NSObject>
-(void)valueWasChangedToHue:(float)hue;
#end
#interface ColorLine : UIButton {
// Get rid of this guy!
//id <ColorLineDelegate> delegate;
}
#property (nonatomic, assign) id <ColorLineDelegate> delegate;
#end
.m:
#import "ColorLine.h"
#implementation ColorLine
#synthesize delegate;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
#end
Perhaps a bit late but to be "ARC compliant", you simply have to replace
#property (nonatomic, assign) id <ColorLineDelegate> delegate;
by
#property (nonatomic, strong) id <ColorLineDelegate> delegate;
Bye.
If you want a weak property, this also works.
#interface MyClass : NSObject {
__weak id <MyClassDelegate> _delegate;
}
#property (nonatomic, weak) id <MyClassDelegate> delegate;
you can also use
#dynamic delegate
in the implementation instead of synthesize.

inheritance working on simulator but not on Iphone!

I have come across a weird error...
I have a class that extends another, getting some variables from it. Its a really simple one.
when i compile the code for the simulator, it works great. When I run in the Iphone, it get an error that states that the vairable is not set!. The code:
parent class header:
#import <UIKit/UIKit.h>
#import "TarefaMap.h"
#interface GenericTarefaTableView : UITableViewController {
TarefaMap* tarefaMap;
TarefaMap* tarefaMapOriginal;
}
#property (nonatomic, retain) TarefaMap* tarefaMap;
#property (nonatomic, retain) TarefaMap* tarefaMapOriginal;
#end
parent class implementation:
#import "GenericTarefaTableView.h"
#implementation GenericTarefaTableView
#synthesize tarefaMap,tarefaMapOriginal;
#end
child class header:
#interface EditTarefaViewController : GenericTarefaTableView <UITextFieldDelegate , UITextViewDelegate> {
Tarefa* tarefa;
NSArray *fieldLabels;
UITextField *textFieldBeginEdited;
BOOL isEdit;
IBOutlet UITableViewCell *cell0;
IBOutlet UITextView* textView;
NSManagedObjectContext* context;
}
#property (nonatomic, retain) NSManagedObjectContext* context;
#property (nonatomic, retain) IBOutlet UITextView* textView;
#property (nonatomic, retain) IBOutlet UITableViewCell *cell0;
#property (nonatomic, retain) Tarefa* tarefa;
#property (nonatomic, retain) UITextField* firstField;
#property (nonatomic, retain) NSArray *fieldLabels;
#property (nonatomic, retain) UITextField *textFieldBeingEdited;
#end
Child class implementation:
#import "EditTarefaViewController.h"
#implementation EditTarefaViewController
#synthesize tarefa, textFieldBeingEdited,firstField,fieldLabels,textView, cell0, context;
NSMutableArray *textFieldarray;
UIActionSheet *actionSheet;
UITableViewCell* cell1;
- (void)viewDidLoad
{
NSLog(#"ViewDidLoad");
[super viewDidLoad];
self.tarefaMap=[[TarefaMap alloc] initWithTarefa:tarefa];
self.tarefaMapOriginal=[[TarefaMap alloc] initWithTarefa:tarefa];
if ([tarefaMapOriginal isEqual:tarefaMap]) {
NSLog(#"SOMOS IGUAIS!!!!!");
}
NSLog(#"Comparando tarefas!!!!!");
if ([tarefaMapOriginal isEqualtoTarefaMap:tarefaMap]) {
NSLog(#"SOMOS IGUAIS2!!!!!");
}
}
This compiles fine on the simulator, but when i Try on the IPhone, I get an error saying that the variables tarefaMap is undeclared, and should be declared on the function...
any thoughts?
#interface EditTarefaViewController : GenericTarefaTableView <UITextFieldDelegate , UITextViewDelegate> {
before that line add this
#class GenericTarefaTableView;
then in .m file add
import "GenericTarefaTableView.h"
and change like in viewdidload
NSLog(#"ViewDidLoad");
[super viewDidLoad];
super.tarefaMap=[[TarefaMap alloc] initWithTarefa:tarefa];
super.tarefaMapOriginal=[[TarefaMap alloc] initWithTarefa:tarefa];
#implementation EditTarefaViewController
before that u have to import TarefaMap.h and also declare this in EditTarefaViewController.h file with like this
#class TarefaMap;