[英]Converting Swift code to Objective-C errors
我试图从swift转换为Objective-C,但出现错误
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print(url)
let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: true)
let host = urlComponents?.host ?? ""
print(host)
return true
}
在对象中尝试:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
printf("%s", url);
NSURLComponents * const urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: true);
NSString * const host = urlComponents.host ?? ""
printf(host);
return true;
}
但是有错误
函数“ URLComponents”的隐式声明在C99中无效
你可以试试
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
printf("%s", url);
NSURLComponents * urlComponents = [[NSURLComponents alloc] initWithURL:url resolvingAgainstBaseURL:true];
NSString * host = urlComponents.host;
NSLog(host);
return true;
}
试试这个。,它将正常工作...
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
NSLog(@"%@", url);
NSURLComponents * const urlComponents = [[NSURLComponents alloc] initWithURL:url resolvingAgainstBaseURL:true];
NSString * const host = urlComponents.host;
NSLog(@"%@", host);
return true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.