Reputation: 1823
I know this question asked several times on this. but I follow both method to solved undeclared identifier self.
I declared @interface in .m class
Upvotes: 1
Views: 225
Reputation: 5695
I believe you are facing these errors because you wrote it inside a C++/C method. If you write it inside a objective-c method, your problem should get resolved.
- (void)cameraCapture {
UIImagePickerController *picker = [UIImagePickerController new];
picker.delegate = self;
}
You can write it in a C/C++ method in the following way.
void cameraCapture(void* object) {
YourCurrentViewController *vc = (__bridge YourCurrentViewController *)object;
UIImagePickerController *picker = [UIImagePickerController new];
picker.delegate = vc;
}
Call it from a Objective-C method in the following way.
CameraCapture(1, "imgName", (__bridge void *)self);
Calling a Objective-C method from C/C++ method.
void CameraCapture(long cCameraClient, const char *imgName, void* object) {
SATController *vc = (__bridge SATController *)object;
UIImagePickerController *picker = [UIImagePickerController new];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing = YES;
[self presentModalViewController:picker animated:YES];
}
Also, you can't directly access self
from a C++ method. You need to pass it to the function. That's the reason for the input void *object
. A void*
is a pointer that has no associated data type with it. It can hold address of any type and can be typecasted to any type.
Upvotes: 2