I am using 3rd party external framework in my objective-c project. I created an swift file in this project to use the framework.
In MyModule-Bridging-Header.h I have import external framework header
#import “ext-service/ext-service.h”
In the ext-service.h there is an constant:
typedef NS_ENUM(NSInteger, service_err_t) {
SERVICE_SUCCESS = 1
}
In my swift code
//Compiler error: use of unresolved identifier ‘SERVICE_SUCCESS’
if result == SERVICE_SUCCESS{
NSLog(“successful!”)
}
But I get compiler error:
use of unresolved identifier ‘SERVICE_SUCCESS’
Why?
The reason to the error you mentioned is SERVICE_SUCESS is unavailable(unknown).
There are 2 possible solutions:
Use service_err_t.SERVICE_SUCCESS instead of SERVICE_SUCESS
result is of type service_err_t then just using .SERVICE_SUCESS
Hope this helps!
Related
when I want use swift file in objective c project and I declare an object from swift class, I get "Use of undeclared identifier" error.
the way that I pass:
coping swift file in project and type #objc before declare swift class
create header file in project manually
set "Defines module" in target to Yes
set objective-C bridging header in target to $(SRCROOT)/$(PRODUCT_MODULE_NAME)-Bridging-Header.h
declare #import "productModuleName-Bridging-Header.h" in objective-c file
use name_of_swift_class *s = [[name_of_swift_class alloc] init];
when I want use swift file in step 6 I get "Use of undeclared identifier" error. why?!!! do I have the mistake?
when I test this steps in new project I don't get error but in project that I want it return error.
thank you for your help
The problem is at Step 5 You should not be importing "productModuleName-Bridging-Header.h" instead you should be importing "productModuleName-Swift.h"
P.S- After making this change clean your project, clear your derived data and build it. It will work. Hope it helps :)
I'm using Toon Boom Harmony and Unity (2017.2), when i build to iOS 11.1 using xcode i get the following error:
Use of undeclared identifier 'UnityCurrentMTLCommandEncoder'
Use of undeclared identifier 'UnityEndCurrentMTLCommandEncoder'
static int registerCallbacks()
{
HarmonySetGetMetalBundleFunc(&UnityGetMetalBundle);
HarmonySetGetMetalDeviceFunc(&UnityGetMetalDevice);
HarmonySetCurrentMTLCommandEncoderFunc(&UnityCurrentMTLCommandEncoder); // Error
HarmySetEndCurrentMTLCommandEncoder(&UnityCurrentEndMTLCommandEncoder); // Error
HarmonySetCurrentMTLCommandBufferFunc(&UnityCurrentMTLCommandBuffer);
HarmonySetGetMetalCommandQueueFunc(&UnityGetMetalCommandQueue);
return 0;
}
Thanks in advance!
Maybe the framework you are using is not swift 4 compatible.
i'm trying to integrate Swift Project in An Objective-C application, I added the header "project-Swift.h" and I added also #objc before Swift class,
I resolved problems of compatibility but these too I didn't find solution for them:
func postCallsChangedNotification() {
NSNotificationCenter.Default.post(name: type(of: self).CallsChangedNotification, object: self)
}
Error: Use of unresolved identifier 'type'
func startSpeakerboxCall(completion: ((_success: Bool) -> Void)?) {
// Simulate the call starting successfully
completion?(_success: true)
/*
Simulate the "started connecting" and "connected" states using artificial delays, since
the example app is not backed by a real network service
*/
DispatchQueue.main.asyncAfter(wallDeadline: DispatchWallTime.now() + 3) {
self.hasStartedConnecting = true
DispatchQueue.main.asyncAfter(wallDeadline: DispatchWallTime.now() + 1.5) {
self.hasConnected = true
}
}
}
Error: Use of unresolved identifier 'DispatchQueue'/ Use of unresolved identifier 'DispatchWallTime'
Could any one help to find why these errors appears however this code works correctly before integration?
It looks like you are using Use legacy Swift Language Version > Yes, So DispatchQueue is not available and you are compiling for Swift 2.3 not 3, you have 2 options :
Use swift 3.
Update your function to 2.3 syntax.
Surely you can use swift files in objective c project.
Just make sure you have imported proper ProjectName.swift.h file in objective c file.
#import "ProjectName-Swift.h"
Refer swift usage in objective c project
I'm working on an objective-c project. I added a swift framework, which gave me errors.
When I touch "command" can find the file. When I use #import also can add "ChartLineView.swift".
But when I implement it as,
ChartLineView *cl = ....
I get an error, " Use of undeclared identifier LineChartView"
What could be wrong?
I guess your are having issue in importing swift library(added via cocoapods) in your Objective C project. Just go in your .m file and import the swift library like this.
#import LineChartView; // i suppose LineChartView is the swift library name.
I have a .m and .h file that generated with Thrift for objective-c based on this link :
http://wiki.apache.org/thrift/ThriftUsageObjectiveC
but there are a lot of error in .m files like :
1. error: duplicate interface definition for class
2. reimplementation of class 'bitlit_thrift_detect_cover_args'
3. use of undeclared identifier '__claim_id'; did you mean 'claim_id'?
4. use of undeclared identifier '__claim_id_isset'
5. reference to local variable 'claim_id' declared in enclosing context
6. error: use of undeclared identifier '__claim_id_isset'
__claim_id_isset = YES;
.....
7. fatal error: too many errors emitted, stopping now [-ferror-limit=]
would you please give me some hints, what is the problem?, is the error related to the xcode setting? my xCode Version is Version 4.6.1
Thanks in advance!
Here is the errors Picture: