我正在制作一个 iOS 代码解释器。我已经完成了所有检查,但到目前为止您只能输入一个命令。我希望用户能够在 UITextView 中输入多个命令。我计划对文本视图执行的操作是将每一行传递给我的 IF 语句行。
有谁知道一种说法,将每一行逐个传递到 if 语句行?
- (IBAction)runCommad:(id)sender {
//Alert
NSString *alertCheck = @"alert(";
NSRange alertCheckRange = [code.text rangeOfString : alertCheck];
//Logger
NSString *logCheck = @"log(";
NSRange logCheckRange = [code.text rangeOfString : logCheck];
if (alertCheckRange.location != NSNotFound) {
//If the compiler sees alert()...
NSString *commandEdit;
commandEdit = code.text;
commandEdit = [commandEdit stringByReplacingOccurrencesOfString:@"alert(" withString:@""];
commandEdit = [commandEdit stringByReplacingOccurrencesOfString:@")" withString:@""];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Syn0" message:commandEdit delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}else if (logCheckRange.location != NSNotFound) {
//If the compiler sees log()...
NSString *commandEdit;
commandEdit = code.text;
commandEdit = [commandEdit stringByReplacingOccurrencesOfString:@"log(" withString:@""];
commandEdit = [commandEdit stringByReplacingOccurrencesOfString:@")" withString:@""];
logFile = [NSString stringWithFormat:@"%@\n%@", logFile,commandEdit];
logTextView.text = logFile;
}
}