Latest 1.0.0
Homepage https://github.com/sgr-ksmt/EnhancedAutoReleasePool
License MIT Copyright (c) 2016 Suguru Kishimoto
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Platforms ios 8.0
Authors

Language
[Xcode]()
[iOS]()
Build Status
Carthage Compatible
Pod Version

EnhancedAutoReleasePool is μ-Library for autoreleasepool.
This library is useful for :

  • do〜try〜catch
  • Returning value from autoreleasepool().

Functions

public func autoreleasepool(@noescape code: () throws -> ()) rethrows
public func autoreleasepool<V>(@noescape code: () throws -> V?) rethrows -> V?
public func autoreleasepool<V>(@noescape code: () throws -> V) rethrows -> V

Usage

// MARK: normal autoreleasepool
(0..<10000).forEach { _ in
    autoreleasepool {
        let imgView = UIImageView(frame: CGRectMake(0, 0, 5000, 5000))
        imgView.image = mockImage()
        imgView.image = nil
    }
}
XCTAssertEqual(arr1.count, 10000)

// MARK: autorelease and return value
var arr2 = [Int]()
(0..<10000).forEach { _ in
    let value = autoreleasepool { () -> Int in
        let imgView = UIImageView(frame: CGRectMake(0, 0, 5000, 5000))
        imgView.image = mockImage()
        imgView.image = nil
        return 1
    }
    arr2.append(value)
}
print(arr2.count)

// MARK: autorelease and return value?
var arr3 = [Int?]()
(0..<10000).forEach { index in
    let value = autoreleasepool { () -> Int? in
        let imgView = UIImageView(frame: CGRectMake(0, 0, 5000, 5000))
        imgView.image = mockImage()
        imgView.image = nil
        return (index % 2 == 0 ? nil : 1)
    }
    arr3.append(value)
}
print(arr3.count)

// MARK: autorelease with try
var arr4 = [Int]()
do {
    try (0..<10000).forEach { index in
        try autoreleasepool {
            if (index == 5000) {
                throw NSError(domain: "", code: 0, userInfo: nil)
            }
            let imgView = UIImageView(frame: CGRectMake(0, 0, 5000, 5000))
            imgView.image = mockImage()
            arr4.append(1)
            imgView.image = nil
        }
    }
} catch ( _) {

}
print(arr4.count)

Requirements

  • iOS 8.0+
  • Xcode 7.0+(Swift 2+)

Installation

Carthage

  • Add the following to your Cartfile:
github 'sgr-ksmt/EnhancedAutoReleasePool'
  • Run carthage update
  • Add the framework as described.

    Details: Carthage Readme

CocoaPods

EnhancedAutoReleasePool is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'EnhancedAutoReleasePool'

and run pod install

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.:muscle:

License

EnhancedAutoReleasePool is under MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "EnhancedAutoReleasePool",
    "version": "1.0.0",
    "summary": "EnhancedAutoReleasePool is u03bc-Library for autoreleasepool.",
    "homepage": "https://github.com/sgr-ksmt/EnhancedAutoReleasePool",
    "authors": {
        "Suguru Kishimoto": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "EnhancedAutoReleasePool/**/*.swift",
    "source": {
        "git": "https://github.com/sgr-ksmt/EnhancedAutoReleasePool.git",
        "tag": "1.0.0"
    },
    "license": {
        "type": "MIT",
        "text": "      Copyright (c) 2016 Suguru Kishimoton      Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:n      The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.n      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.n"
    }
}

Pin It on Pinterest

Share This