This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import Foundation
// Write your code here...
func varProcessor(_ n: Any) {
let nInt = n as? Int ?? 0 // 如果n是整形数,nInt将会被赋予n的值
let nString = n as? String ?? "" // 如果n是字符串,nString将会被赋予n的值
switch n {
case is Int:
// 如果n是整形,这里的代码将会被执行
case is String:
// 如果n是字符串,这里的代码将会被执行
default:
print("An error occurred.")
}
// 测试用,不需要改动
let test: [Any] = [0, 2, 0.2, "Hello"]
for item in test {
varProcessor(item)