I was creating an NSObject class for doing web service. But while creating the protocol ,an error comes displaying"cannot find protocol declaration for NSObject" .In Xcode 4 I never came across such problems.Now I am using Xcode 6. Pls help me. Code is as below.
#protocol web <NSObject>
-(void)(NSArray *)urlArray;
#end
#import <Foundation/Foundation.h>
#interface Webclass : NSObject
#end
Write your protocol under #import and put name on your method
#import <Foundation/Foundation.h>
#protocol web <NSObject>
-(void)methodName:(NSArray *)urlArray;
#end
#interface Webclass : NSObject
#end
Related
At first, in LoadingVC.h I declare a protocol:
#protocol VideoWorker <NSObject>
#required
#property (nonatomic) float progress;
#property (nonatomic) BOOL done;
-(void)beginWorking;
#end
#interface LoadingVC : UIViewController <UIAlertViewDelegate>
...
#end
then in BlurWorkerGPU.h
...
#import "LoadingVC.h"
#interface BlurWorkerGPU : NSObject <VideoWorker> {
...
}
- (void)beginWorking;
#property(nonatomic)float progress;
#property(nonatomic)BOOL done;
...
#end
However, llvm says that
"No type or protocol named 'VideoWorker'"
which is strange since I am importing the header where the protocol is defined. Any clues?
You should forward declare protocol in .h files before you use it. Put this in the top of BlurWorkerGPU.h
#protocol VideoWorker;
check whether you are importing "BlurWorkerGPU.h" in "LoadingVC.h"
Possible solutions are
import protocol
#import
YOURPROTOCOLNAME
import Class in which protocol is declared
#import "YOURCLASSWHICHDECLAREDPROTOCOL.h"
Use #Class to import the class
#class YOURCLASSWHICHDECLAREDPROTOCOL;
I am trying to figure out how to take the delegate in LocationViewController and SetScoringTableViewController and implement both of them in GameDetailsTableViewController. LocationViewControllerDelegate was already working, but when I added the new SetScoringTableViewController, the program had an error.
LocationViewController.h
#import "ViewController.h"
#class LocationViewController;
#protocol LocationViewControllerDelegate <NSObject>
- (void)addItemViewController:(LocationViewController *)controller didFinishEnteringItem:(NSString *)name;
#end
#interface LocationViewController : UIViewController
#property (nonatomic, weak) id <LocationViewControllerDelegate> delegate;
#end
SetScoringTableViewController.h
#import <UIKit/UIKit.h>
#import "GameDetailsTableViewController.h"
#import "LocationViewController.h"
#class SetScoringTableViewController;
#protocol SetScoringTableViewControllerDelegate <NSObject>
- (void)addItemViewControllerSS:(SetScoringTableViewController *)SScontroller didFinishEnteringItemSS:(NSString *)SSname;
#end
#interface SetScoringTableViewController : UITableViewController
#property (nonatomic, strong) id <SetScoringTableViewControllerDelegate> SSdelegate;
#end
GameDetailsTableViewController.h
#import <UIKit/UIKit.h>
#import "LocationViewController.h"
#import "SetScoringTableViewController.h"
#interface MainViewController : UITableViewController <LocationViewControllerDelegate, SetScoringTableViewControllerDelegate>
When I run this I get an error: "Cannot find protocol declaration for 'SetScoringTableViewControllerDelegate' even though I have.
The only way I have found to fix this problem is to put the "SetScoringTableViewController delegate in the LocationView Controller, but I know that is not right. Any help would be greatly appreciated.
You have a dependency loop:
SetScoringTableViewController.h
#import "GameDetailsTableViewController.h"
GameDetailsTableViewController.h
#import "SetScoringTableViewController.h"
But it looks like you can remove the #import "GameDetailsTableViewController.h" as there is no mention of it in the header file.
What you're experiencing is an an #import cycle. To break the import loop
remove this import line:
#import "GameDetailsTableViewController.h"
from SetScoringTableViewController.h and put it in a .m file.
Try to separate the delegate on a different .h file.
I plan to make a QRBar scanner, I found a source called "IOS7_BarcodeScanner" which implement the any types of scanner to be used. I try the demo sources, and it works like a charm. But when I comes to creating my own project, and implement it. Unknown types name UIBezierPath, even I copy and paste exactly the files from demo source. It doesn't work. I have import the frameworks accordingly.
Barcode.h
#import <Foundation/Foundation.h>
#import AVFoundation;
#interface Barcode : NSObject
+ (Barcode * )processMetadataObject:(AVMetadataMachineReadableCodeObject*) code;
- (NSString *) getBarcodeType;
- (NSString *) getBarcodeData;
- (void) printBarcodeData;
#end
Barcode.m
#import "Barcode.h"
#interface Barcode()
#property (nonatomic, strong) UIBezierPath *cornersPath;
#end
#implementation Barcode
#end
Error
#property (nonatomic, strong) UIBezierPath *cornersPath;
Message
Unknown type name 'UIBezierPath'
Property with 'retain (or strong)' attribute must be of object type'
Import UIKit framework
Objective-C :
#import <UIKit/UIKit.h> OR #import UIKit;
Swift
import UIKit
Try adding this at the top of your .h file:
#import <UIKit/UIKit.h>
I am new to objective C and trying to implement objection (dependency injector).
But its not working below is the code i am using
My Protocol File
#import <Foundation/Foundation.h>
#protocol InfoquestProtocolTest <NSObject>
-(void):nothing;
#end
My .h file is below
#import <Foundation/Foundation.h>
# import "InfoquestProtocolTest.h"
#interface InfoquestImplementation : NSObject<InfoquestProtocolTest>
#end
my .m file implementing protocol
#import "InfoquestImplementation.h"
#implementation InfoquestImplementation
-(void):nothing{}
#end
Code for module file of objection
#import "InfoquestTestConf.h"
#import <Objection/Objection.h>
#import "InfoquestViewController.h"
#import "InfoquestImplementation.h"
#implementation InfoquestTestConf
-(void)configure
{
[self bindClass:[InfoquestImplementation class] toProtocol:#protocol(InfoquestProtocolTest)];
}
#end
Code for getting object from objection
JSObjectionInjector *injector = [JSObjection createInjector];
[JSObjection setDefaultInjector:injector];
InfoquestTestConf *Module = [[InfoquestTestConf alloc] init];
[injector withModule: Module];
id<InfoquestProtocolTest> testing2 = [injector getObject:[#protocol(InfoquestProtocolTest)];
But when i try to call using [testing2 nothing]; i am getting error and autocomplete doesnt show up nothing.
Thanks
gaurav
You have a syntax error:
You should replace:
-(void):nothing;
with
-(void)nothing;
here is an error in your syntax.please change :
-(void):nothing;
to:
-(void)nothing;
Hence you are using custom delegates. So first you have to set the delegate to your class where you are implementing the method of your protocol.
i've worked with delegation before. i know how to create delegation from a superview to a subview class. however, i'm trying to do it the opposite way using the same approach but it's not working! is delegation meant only to work one way or is there a way/trick to use it as a two way communication between the classes? I'm receiving an error at the parent/superview .h class which is:
Cannot find protocol definition for 'SubViewControllerDelegate'
my code goes like this:
subview.h
#import <UIKit/UIKit.h>
#import "SuperViewController.h"
#protocol SubViewControllerDelegate <NSObject>
- (void)someMethod:(NSData *)data;
#end
#interface SubViewController : UIViewController
#property (weak, nonatomic) id <SubViewControllerDelegate> delegate;
#end
subview.m:
[self.delegate someMethod:data];
SuperView.h
#import <UIKit/UIKit.h>
#import "SubViewController.h"
#interface SuperViewController : UIViewController <SubViewControllerDelegate>
#end
SuperView.m:
#pragma mark - SubView Controller Delegate Methods
- (void)someMethod:(NSData *)data{
NSLog(#"%#", data);
}
am i doing anything wrong or missing out anything?
You have an "import-cycle", because "SuperViewController.h" imports "SubViewController.h" and vice versa.
Removing the #import "SuperViewController.h" in "SubViewController.h"
should solve the problem.
If you really need that class to be declared in "SubViewController.h", use
#class SuperViewController; to avoid the import-cycle.
Remark: The <SubViewControllerDelegate> protocol declaration is probably not
needed in the public interface "SuperViewController.h" at all.
In "SuperViewController.h", declare the class as
#interface SuperViewController : UIViewController
In "SuperViewController.m", define a class extension with the protocol:
#interface SuperViewController () <SubViewControllerDelegate>
#end