我在 Objective C 中使用了这段代码:
@implementation KDOrderInfo
- (id)performDefaultImplementation {
NSString *theRequest = [self directParameter];
NSDictionary *arguments = [self evaluatedArguments];
NSLog(@"arguments = %@ %ld",arguments, [arguments count]);
NSLog(@"theRequest----> %@",theRequest);
/*.......
.....*/
return @YES
}
这段代码在 Objective C 中运行正常。
我将此代码转换为 Swift 代码,如下所示:
class OrderInfo : NSScriptCommand {
override func performDefaultImplementation() -> AnyObject! {
let theRequest: AnyObject! = self.directParameter
let arguments = self.evaluatedArguments
println("arguments = \(arguments) argumentsCount = \(arguments.count)")
println("theRequest----> \(theRequest)")
/*.......
.....*/
return "OK"
}
}
当我运行我的 applescript 时,我收到错误(InfoMaker 是我的应用程序的名称):
InfoMaker 收到错误:处理程序某个对象未定义。
方法 :
override func application(theApp:NSApplication,delegateHandlesKey theKey:String) -> Bool{
println("scripting key = \(theKey)");
let thekeys = ["pathToXML", "saveXMLFlag", "webserviceName","methodName","pathToInfoFiles","fileToCheck","scriptingProperties"]
if thekeys.containsString(theKey.lowercaseString, searchcase:NSStringCompareOptions.CaseInsensitiveSearch) {
//[self prefsToVars];
println("YES")
return true;
} else {
println("NO")
return false
}
}
在我的应用程序委托中,对 applescript 的响应正常。
我还尝试了 Apple 的“SimpleScriptingVerbs”示例,并且在 Swift 实现中遇到了相同的错误。我希望有人能帮助找到问题并提出建议。