繁体   English   中英

我需要将NSString变量放在initWithSource函数中的另一个字符串中,但是我不知道如何

[英]I need to put an NSString variable in another string inside the initWithSource function, but I don't know how

我需要在另一个字符串代码之间放置一个NSString变量,以在其他代码之间获取“ pathToSerialDevice”变量。 像这样:

NSAppleScript *appleScript = [[NSAppleScript alloc]
                initWithSource:@"Tell application \"Terminal\" \n\
                                do script with command \"screen %@", pathToSerialDevice, "\" in front window\n\
                                end tell"];

我的pathToSerialDevice字符串来自一个文本字段

pathToSerialDevice = [NSString stringWithFormat:_pathTextField.stringValue];

当我在日志中显示它时,它会起作用:

NSLog(@"Your path is %@", pathToSerialDevice);

怎么做,但是在NSAppleScript中呢? 现在不起作用,我也不知道该怎么做。 请帮我。

PS我在OS X 10.10上有Xcode 6.1,它是OS X应用程序。

initWithSource:使用常规字符串,而不是格式字符串。 阅读有关差异的这些文档

最简单的方法是制作另一个字符串:

NSString *pathToSerialDevice = [NSString stringWithFormat:_pathTextField.stringValue];
NSString *source = [NSString stringWithFormat:@"Tell application \"Terminal\" \n\
                                              do script with command \"screen %@ \" in front window\n\
                                              end tell", pathToSerialDevice];

NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:source];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM