ios - Removing NSNull from Key Path Results with Partial Matches -


given data structure mismatching objects:

 1> import foundation  2> let d: nsdictionary = ["test": [["name": "dick", "age": 101], ["name": "jane"]]] 

valueforkeypath: return values total number of sub-objects:

 3> d.valueforkeypath("test.name") as! nsarray  $r2: nsarray = "2 values" {    [0] = "dick"    [1] = "jane"  } 

even when leaf key doesn't exist in cases:

4> d.valueforkeypath("test.age") as! nsarray  $r3: nsarray = "2 values" {   [0] = int64(101)   [1] = {     nsobject = {      isa = nsnull     }   } } 

is there way existing ages, without instances of nsnull?

@distinctunionofarrays , on helps if there multiple sub-objects without leaf key, you're still left 1 nsnull.

on side note, if leaf key entirely unknown, nsnulls returned:

5> d.valueforkeypath("test.dog") as! nsarray $r4: nsarray = "2 values" {   [0] = {     nsobject = {       isa = nsnull     }   }   [1] = {     nsobject = {       isa = nsnull     }   } } 

in contrast, if root key unknown, nil returned:

6> d.valueforkeypath("dog.name") $r5: anyobject? = nil 

this logic strikes me inconsistent, perhaps i'm missing something?

var array:[anyobject] = [1.1, 1.2, 1.3, 1.4, 1.5, 1.6, nsnull(),1.7, 1.8, 1.9]

let newarr = array.filter{ !($0 nsnull) }

newarr


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -