我想将每个日期转换为类型列表中的类型,例如 {string,integer,text,...} ,如下所示:
set ret to {}
set aStringList to {"abc","123","def","456"}
set typeList to {string,integer,string,integer}
repeat with i from 1 to (count aStringList)
set theStr to item i of aStringList
set end of ret to theStr as (item i of typeList)
end repeat
log ret
是否可以实施?
答案 0 :(得分:1)
您无法在运行时使用动态强制,在编译时会对强制进行评估。
你必须做那样的事情:
set ret to {}
set aStringList to {"abc", "123", "def", "456"}
set typeList to {string, integer, string, integer}
repeat with i from 1 to (count aStringList)
set theStr to item i of aStringList
set classIndex to item i of typeList
if classIndex = string then
set end of ret to theStr as string
else if classIndex = integer then
set end of ret to theStr as integer
end if
end repeat
log ret