How to parse array from description in Swift 4?

前端 未结 2 941
一生所求
一生所求 2021-01-26 13:05

I\'m learning Swift 4, and I have an algorithm that output the base 64 description of an array, like that:

extension String {

    func fromBase64()         


        
2条回答
  •  自闭症患者
    2021-01-26 13:33

    Here is the way you can convert your string into Int array:

    var toString = output.fromBase64() //"[1, 2, 4, 65]"
    if let str = toString {
        let chars = CharacterSet(charactersIn: ",][ ")
        let split = str.components(separatedBy: chars).filter { $0 != "" }.flatMap { Int($0)}
        print(split)  //[1, 2, 4, 65]
    }
    

提交回复
热议问题