Объективные кавычки и переменные - PullRequest
1 голос
/ 03 июля 2010

Я пытаюсь сделать что-то вроде этого:

NSAppleScript *sendCharlieImput = [[NSAppleScript alloc] initWithSource:@"tell application \"terminal\" to do script " charlieImputSelf " in front window"];
[sendCharlieImput executeAndReturnError:nil];

Переменная charlieImputSelf будет помещена в окно терминала в качестве команды. НО мне нужно положить charlieImputSelf между 2 qoutes (как выше). Это явно не правильный путь. Может кто-нибудь помочь?

Спасибо! Илия

Ответы [ 2 ]

10 голосов
/ 03 июля 2010

Чтобы быть успешным, вам нужно принять документацию. Начните здесь .Затем перейдите на прочитайте это .

Если вы зададите вопрос о SO на каждой строке кода, это не приведет к успеху.

Ответитьэтот вопрос вы хотите stringWithFormat::

[NSString stringWithFormat: @"some random string \"with quotes\" and %@ word in the middle.", @"this"]; 
3 голосов
/ 03 июля 2010

Использование NSString * +stringWithFormat: метод:

NSAppleScript *sendCharlieImput = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"tell application \"Terminal\" to do script %@ in front window", charlieImputSelf]];
...