[swift-evolution] Update the signature of ObjectiveC.autoreleasepool [SR-842]

Dmitri Gribenko gribozavr at gmail.com
Mon Mar 21 13:43:24 CDT 2016


On Mon, Mar 21, 2016 at 9:37 AM, Jordan Rose <jordan_rose at apple.com> wrote:
> -1 for the signature change. The most common case of autoreleasepool does
> not return a value and has a multi-statement body that prevents the result
> type from being inferred. This needs to continue to work:
>
> autoreleasepool {
>   foo()
>   bar()
> }

It seems to work for me:

func poolPush() {}
func poolPop() {}

public func autoreleasepool<Result>(@noescape code: () throws ->
Result) rethrows -> Result {
  poolPush()
  defer { poolPop() }
  return try code()
}

func foo() {}
func bar() {}

autoreleasepool {
  foo()
  bar()
}

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list