<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I have a pending pull request that needs a little more work around NSPredicates, but in my testing on darwin foundation, I’ve discovered what appears to be an obj-c nullability annotation bug. When constructing a block predicate, the type of the block is this:<div class=""><br class=""></div><div class="">(AnyObject, [String: AnyObject]?) -> Bool</div><div class=""><br class=""></div><div class="">However, the type signature of evaluateObject(_:<span class="">substitutionVariables:) is</span></div><div class=""><span class=""><br class=""></span></div><div class="">(AnyObject<b class="">?</b>, [String: AnyObject]?) -> Bool</div><div class=""><br class=""></div><div class="">Note the optional AnyObject here. In Xcode 7.2 with swift 2.1, the following code causes an EXC_BAD_ACCESS signal when calling evaluateWithObject: in a playground:</div><div class=""><br class=""></div><span class="">let pred = NSPredicate(block: { (obj: AnyObject, bindings: [String: AnyObject]?) -> Bool in<br class=""> print(obj)<br class=""> return false<br class="">})<br class="">print(pred.evaluateWithObject(nil))</span><div class=""><span class=""><br class=""></span></div><div class="">because obj is in fact optional here, but the type of the block does not allow for this.</div><div class=""><br class=""></div><div class="">There are two possible approaches here; removing the optional type from evaluateWithObject, or adding it to the block constructor for NSPredicate. Such a change is also presumably trivial to port back to darwin foundation, as that at minimum would need to merely change nullability annotations for these components of NSPredicate. These involve a public-api change which by my understanding needs to go through the swift evolution process.</div><div class=""><br class=""></div><div class="">Before sending this over to swift-evolution which is already pretty high-traffic, I wanted to float this here to make sure that this is appropriate for that process. Is it enough to draft a proposal outright or for comprehensiveness sake should I also send this out to that list to open discussion first?</div><div class=""><br class=""></div><div class="">Is there anyone on this list that has an opinion over which approach to take for changing the api here?</div><div class=""><br class=""></div><div class="">Thanks!</div><div class=""><span class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">--</div><div class="">Kevin Lundberg</div><div class=""><a href="mailto:kevin@klundberg.com" class="">kevin@klundberg.com</a></div></div></div></div>
</div>
<br class=""></span></div></body></html>