d
This commit is contained in:
23
toSwift
23
toSwift
@@ -15,6 +15,7 @@ let globalReplacements = {
|
||||
"number": "Float",
|
||||
"):": ") ->",
|
||||
"interface": "protocol",
|
||||
"})": "}", // forEach
|
||||
};
|
||||
|
||||
console.log(`Converting '${fileSrc}' to '${fileDst}'`);
|
||||
@@ -40,11 +41,31 @@ function convert(line) {
|
||||
}
|
||||
result = protocolReplace(result);
|
||||
result = typeArrayReplace(result);
|
||||
result = forEachReplace(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
var isProtocol = false;
|
||||
|
||||
// x.forEach(y => { -> x.forEach { y in
|
||||
function forEachReplace(line) {
|
||||
if (!line.includes("forEach")) {
|
||||
return line;
|
||||
}
|
||||
|
||||
let partsFE = line.split("forEach");
|
||||
let identifier = partsFE[0];
|
||||
let closure = partsFE[1];
|
||||
|
||||
let partsC = closure.split(" => ");
|
||||
let bracketAndVar = partsC[0];
|
||||
let bracket = partsC[1];
|
||||
let variable = bracketAndVar.substring(1);
|
||||
let result = `${identifier}forEach { ${variable} in`;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
var isProtocol = false;
|
||||
// interface -> protocol
|
||||
function protocolReplace(line) {
|
||||
if (line.includes("protocol")) {
|
||||
|
||||
Reference in New Issue
Block a user