I have a function must return a string, but my problem is Asynchronous Tasks. How to wait and get results out completion of featureTable.queryFeatures. Thanks!
func <SPAN class="token function">GetValueSum</SPAN><SPAN class="punctuation token">(</SPAN>geo <SPAN class="operator token">:</SPAN> AGSGeometry <SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> String<SPAN class="punctuation token">{</SPAN>
var strReturn <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>
let queryParameters <SPAN class="operator token">=</SPAN> <SPAN class="token function">AGSQueryParameters</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
queryParameters<SPAN class="punctuation token">.</SPAN>geometry <SPAN class="operator token">=</SPAN> geo
queryParameters<SPAN class="punctuation token">.</SPAN>spatialRelationship <SPAN class="operator token">=</SPAN> AGSSpatialRelationship<SPAN class="punctuation token">.</SPAN>intersects
queryParameters<SPAN class="punctuation token">.</SPAN>outSpatialReference <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>mapView<SPAN class="punctuation token">.</SPAN>spatialReference
self<SPAN class="punctuation token">.</SPAN>featureTable<SPAN class="operator token">?</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">queryFeatures</SPAN><SPAN class="punctuation token">(</SPAN>with<SPAN class="operator token">:</SPAN> queryParameters<SPAN class="punctuation token">,</SPAN> completion<SPAN class="operator token">:</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="punctuation token">(</SPAN>result<SPAN class="operator token">:</SPAN> AGSFeatureQueryResult<SPAN class="operator token">?</SPAN><SPAN class="punctuation token">,</SPAN> error<SPAN class="operator token">:</SPAN> Error<SPAN class="operator token">?</SPAN><SPAN class="punctuation token">)</SPAN> in
<SPAN class="keyword token">if</SPAN> error <SPAN class="operator token">!=</SPAN> nil <SPAN class="punctuation token">{</SPAN>
<SPAN class="token function">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Error in function"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="keyword token">if</SPAN> let features <SPAN class="operator token">=</SPAN> result<SPAN class="operator token">?</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">featureEnumerator</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>allObjects <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">for</SPAN> feature in features <SPAN class="punctuation token">{</SPAN>
strReturn <SPAN class="operator token">+</SPAN><SPAN class="operator token">=</SPAN> <SPAN class="string token">"\(feature.attributes["</SPAN>Label1<SPAN class="string token">"]!); "</SPAN>
<SPAN class="token function">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"For string: \(strReturn)"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="token function">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Return string: \(strReturn)"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> strReturn
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>The result:

But the "Return string" must be the last "For string".
Thanks for help!