Reputation: 363
When I define my block in my .h file, there comes an issue:
Unknown type name
NSString
My code is below:
typedef void(^CancelBlock)();
typedef void(^ConfirmBlck)(NSString *); // this line comes the error
#import <UIKit/UIKit.h>
@interface LMLUpspringView : UIView
@property (nonatomic, copy) CancelBlock cancelBlock;
@property (nonatomic, copy) ConfirmBlck confirmBlock;
@end
But, why is my first block ok and the second report's an error?
Upvotes: 0
Views: 4644
Reputation: 2335
In latest versions of xcode you can simply specify
#import <Foundation/NSString.h>
any NS Foundation class can be imported as needed.
Upvotes: 0
Reputation: 675
position declaration uikit import then follow:
// declare
@property(nonatomic,strong)void(^ConfirmBlck)(NSString * string);
// define
[self setConfirmBlck:^(NSString *indexpVal) { }];
// call
if (self.ConfirmBlck) {
self.ConfirmBlck(selectedVal);
}
Upvotes: -1
Reputation: 8322
you need to declare block as below
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
typedef void(^ConfirmBlck)(NSString * string);
Upvotes: 2
Reputation: 26876
You define block above the #import <UIKit/UIKit.h>
(in the .h file), so there did not import the NSString, you should cut the #import <UIKit/UIKit.h>
above the block define.
Upvotes: 3