Created
January 30, 2021 09:16
-
-
Save Heilum/ec459dabe96de13c453032fcd83e4dd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Collection+SF.swift | |
// PanoAI | |
// | |
// Created by Forever Positive on 2021/1/30. | |
// | |
import Foundation | |
extension Array where Element == Optional<Any>{ | |
var trimed:[Any] { | |
var newArray = [Any]() | |
for item in self{ | |
if let item = item as? [Any?] { | |
newArray.append(contentsOf: item.trimed) | |
}else if item is NSNull || item == nil { | |
//skip | |
}else if let item = item{ | |
newArray.append(item) | |
} | |
} | |
return newArray | |
} | |
} | |
extension Dictionary where Key == String, Value == Optional<Any> { | |
var trimed:[Key: Any] { | |
return self.compactMapValues({ v in | |
if let dic = v as? [String:Any?] { | |
return dic.trimed | |
}else if let _ = v as? NSNull { | |
return nil; | |
}else if let array = v as? [Any?] { | |
return array.trimed; | |
}else{ | |
return v; | |
} | |
}) | |
} | |
} |
Author
Heilum
commented
Jan 30, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment