'__strong' only applies to objective-c object or block pointer types; type here is 'void *'
this the "__strong" line in my AVAudioPlayer.h file (which is an imported framework)
#interface AVAudioPlayer : NSObject {
#private
__strong void *_impl;
}
my .h file looks like this
#import <UIKit/UIKit.h>
#import <AVFoundation/AVAudioPlayer.h>
#interface excerViewController : UIViewController <AVAudioPlayerDelegate,UIAccelerometerDelegate>
#property (weak, nonatomic) IBOutlet UILabel *avgLabel;
#property (weak, nonatomic) IBOutlet UILabel *modeLabel;
#property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
#property (weak, nonatomic) IBOutlet UILabel *timeLabel;
#property (weak, nonatomic) IBOutlet UIButton *playButton;
#property int subScore;
#property int score;
#property int seconds;
#property int moments;
#property NSMutableString *average;
#property double avg;
#property BOOL locked;
#property double delta;
#property UIAccelerometer *accel;
#property AVAudioPlayer *player;
-(void)drawEnergy:(double)energy;
#end
I can't for the life of me figure out why I'm getting this error. One other person on StackOverflow had this issue, and it isn't the reason i'm getting it
( '__strong' only applies to objective-c object or block pointer types; type here is XXX" warning)
Because void* is a pointer to an argument with no type, and not a true object, __strong does not apply to it.
Related
I am compiling code to avoid Retain Cycle, When I use weak , I got this error: 1. property of weak attribute must be of object type; 2. Unknown type name 'OrderEntry'. What is wrong with the code? Thanks!
// OrderEntry.h
#import <Foundation/Foundation.h>
#import "OrderItem.h"
#import "Address.h"
#interface OrderEntry : NSObject
#property (strong, nonatomic)OrderItem *orderItem;
#property (strong, nonatomic)Address *shippingAddress;
#property (strong, nonatomic) NSString *orderID;
#end
// OrderItem.h
#import <Foundation/Foundation.h>
#import "OrderEntry.h"
#interface OrderItem : NSObject
#property (strong,nonatomic) NSString *name;
#property (weak, nonatomic) OrderEntry *entry;
#end
The problem is with both .h files each including the other. This causes a circular dependency on the declarations. The simple solution is to use forward declarations instead.
OrderEntry.h:
#import <Foundation/Foundation.h>
#import "Address.h"
#class OrderItem;
#interface OrderEntry : NSObject
#property (strong, nonatomic) OrderItem *orderItem;
#property (strong, nonatomic) Address *shippingAddress;
#property (strong, nonatomic) NSString *orderID;
#end
OrderItem.h:
#import <Foundation/Foundation.h>
#class OrderEntry;
#interface OrderItem : NSObject
#property (strong, nonatomic) NSString *name;
#property (weak, nonatomic) OrderEntry *entry;
#end
Then you import the .h files in the .m file.
The general guideline is to import the fewest possible .h files in another .h file. Use forward declarations for classes and protocols whenever possible.
Please consider the following header (LessonDelegate.h):
#import "Lesson.h"
#ifndef BirdEye_LessonDelegate_h
#define BirdEye_LessonDelegate_h
#protocol LessonDelegate <NSObject>
- (BOOL) lesson:(Lesson*)lesson didRequestNavigation:(NSString*) url;
#end
#endif
It gives an error here:
- (BOOL) lesson:(Lesson*)lesson didRequestNavigation:(NSString*) url;
saying "Expected a type". It complains about Lesson type even if it is declared and successfully used in other classes.
Lesson.h is where it is supposed to be (same folder) and looks like this:
#import <Foundation/Foundation.h>
#import "SimpleManifest.h"
#import "Activity.h"
#import "LessonDelegate.h"
#interface Lesson : Activity
#property (retain, nonatomic) NSString *url;
#property (retain, nonatomic) SimpleManifest *manifest;
#property (retain, nonatomic, readonly) Activity *runningActivity;
#property (weak) id<LessonDelegate> delegate;
- (id) initWithUrl:(NSString*) aurl;
- (NSString*) deteails;
#end
Where's my mistake?
LessonDelegate.h
#class Lesson; // there was a missing ; here
#protocol LessonDelegate <NSObject>
- (BOOL) lesson:(Lesson*)lesson didRequestNavigation:(NSString*) url;
#end
Lesson.h
#import <Foundation/Foundation.h>
#import "SimpleManifest.h"
#import "Activity.h"
#import "LessonDelegate.h"
#interface Lesson : Activity
#property (retain, nonatomic) NSString *url;
#property (retain, nonatomic) SimpleManifest *manifest;
#property (retain, nonatomic, readonly) Activity *runningActivity;
#property (weak) id<LessonDelegate> delegate;
- (id) initWithUrl:(NSString*) aurl;
- (NSString*) deteails;
#end
How do I parse this JSON in Objective C? I've been using jsonmodel.com's code to parse.
{
"found":10958,
"start":3141,
"hits":[
{
"pid":"76493",
"title":"Beton Armu00e9",
"artist":"Raiden",
"genre":"Dubstep",
"image":"A76493_BetonArm_BetonArm.jpg",
"label":"Offkey",
"year":"2011",
"price":9.99,
"release":"Beton Armu00e9",
"type":"Album",
"tracks":{
"0":{
"name":"Barbican",
"file":"A76481_Barbican.mp3",
"tracknum":1,
"pid":"76481"
},
"1":{
"name":"Trinity",
"file":"A76482_Trinity.mp3",
"tracknum":2,
"pid":"76482"
},
"2":{
"name":"Tricorn",
"file":"A76483_Tricorn.mp3",
"tracknum":3,
"pid":"76483"
},
"3":{
"name":"Brutalist",
"file":"A76484_Brutalist.mp3",
"tracknum":4,
"pid":"76484"
},
"4":{
"name":"Trellick",
"file":"A76485_Trellick.mp3",
"tracknum":5,
"pid":"76485"
}
}
}
]
}
JSONModel expects a pointer string to declare the keys, but the keys here are numbers. This is what I need, but won't work:
#import "JSONModel.h"
#import "songParentModel.h"
#protocol albumModel #end
#interface albumModel : JSONModel
#property (strong,nonatomic) NSString *title;
#property (strong,nonatomic) NSString *image;
#property (strong,nonatomic) NSString *artist;
#property (strong,nonatomic) songParentModel *0; // THIS DOESN'T WORK (of course)
#end
I just need to get the first track, but it would be nice to know how to get them all.
My best guess for a solution would be to stop using JSONModel and parse the JSON with some other simplified method.
Create a class like this :
The header:
#import "JSONModel.h"
#protocol Track #end
#interface Track : JSONModel
#property (strong, nonatomic) NSString* name;
#property (assign, nonatomic) NSString* file;
#property (assign, nonatomic) int tracknum;
#property (strong, nonatomic) int pid;
#end
Leave the implementation as default.
now in your model add this property:
#property (strong, nonatomic) NSArray<Track>* allTracks;
And also change the implementation for +(JSONKeyMapper*)keyMapper and add the below item to your dictionary.
+(JSONKeyMapper*)keyMapper
{
return [[JSONKeyMapper alloc] initWithDictionary:#{
#"tracks":#"allTracks",
}];
}
In this way you get an array of all the tracks and you can also get all the details for each track as well.
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.
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;