在Swfit 2.0的Xcode
7測試版5.你可以做到以下幾點:
let array = [["VacancyTitle": "PHP Engineer","VacancyJobType": "Full Time",
"EmployerCompanyName": "Vodafone",
"EmployerCompanyLogo": "d022813eadb769c3a972221621552d04.jpg",
"EmployerAddress": "10th Floor, Aitken Spence Tower 2, 315, Vauxhall Street, Colombo 02, Sri Lanka.ty",
"UserID": "144",
"block_count": "0"
]]
let mapResult = array.map { $0["EmployerAddress"] }
let employerAddress = mapResult[0]!
let components = employerAddress.characters.split{$0 == ","}.map{String($0)}
let count = components.count
let finalString = components[count - 2] + ", " + components[count - 1] //" Colombo 02, Sri Lanka.ty"
的Xcode 6.4雨燕1.2:
let array = [["VacancyTitle": "PHP Engineer","VacancyJobType": "Full Time",
"EmployerCompanyName": "Vodafone",
"EmployerCompanyLogo": "d022813eadb769c3a972221621552d04.jpg",
"EmployerAddress": "10th Floor, Aitken Spence Tower 2, 315, Vauxhall Street, Colombo 02, Sri Lanka.ty",
"UserID": "144",
"block_count": "0"
]]
let mapResult = array.map { $0["EmployerAddress"] }
let employerAddress = mapResult[0]!
let components = split(employerAddress) {$0 == ","}
let count = components.count
let finalString = (components[count - 2] + ", " + components[count - 1])
嘗試使用一個string.Split方法,然後訪問返回的數組和ge t從那裏的值 – DieVeenman