Recently, I have been wondering how to judge the Anyobject type is empty, like the previous OC has nil to judge it, but it can not use this method to judge;
And I need to use the Anyobject type as the return value in many data requests, studied for a long time did not find an effective way of judging, today carefully studied the next its data structure, finally found the method;
First of all, the analysis of its data structure, the following sub-data and no data when the distinction:
1. When there is data:
▿optional<anyobject>
▿some:2 elements
▿[0]: Elements
▿[0]: 2 elements
-. 0:systime
▿[1]: 2 elements
-. 0:contxt
▿[1]: Elements
▿[0]: 2 elements
-. 0:systime
▿[1]: 2 elements
-. 0:contxt {...}
2. When there is no data:
Optional<anyobject>
-Some: <null>
From the above two cases can be seen in the data when it is used in a count of the way to store, a bit like an array, then it should be similar to the array to determine the number of elements to call the Count function to determine whether there are elements;
And there is no value of the situation will find that it gives the <null>, which reminds me of the Nsnull class, but I use this way to judge the time is not good, the compilation can not pass;
Therefore, the final solution is to use it as a container to handle, storage elements in the container, then you can get the number of elements in the container, if the number is 0, then there is no element in the container;
The final judgment is that Anyobject is an empty operation that relies on the count function to anyobject.count<=0 that means Anyobject is empty.