Latest 1.0.6
Homepage https://github.com/minacle/AAA
License MIT
Platforms ios 8.0, osx 10.10, tvos 9.0, watchos 2.0
Authors

release Travis license Carthage compatible platform

An Any Accessory.

An Any Accessory?

Well.. it sounds great. So, what is it?

You probably encountered at least once the situation that upcasted [Any], [AnyHashable: Any] or anything as Any. If so, you wrote as follows:

func tion(_ anAny: Any) -> Int {
    var anArray: [Int]?
    var aDictionary: [String: Any]?
    var result = 0
    if anAny is [Int] {
        anArray = anAny as! [Int]
    }
    else if anAny is [String: Int] {
        aDictionary = anAny as! [String: Int]
    }
    if let anArray = anArray {
        result = ((anArray[3] as? [Int])?[9] as? [Int])?[27]? ?? 0
    }
    else if let aDictionary = aDictionary {
        result = (aDictionary["3"] as? [String: [String: Int]])?["9"]?["27"] ?? 0
    }
    return result
}

No, stop! Please have mercy on me!

Okay. I’ll show some mercy to you.

let package = Package(
name: "AWESOME_APP",
dependencies: [
.Package(url: "https://github.com/minacle/AAA.git", majorVersion: 1),
]
)


- **Cartfile** (Using *[Carthage](https://github.com/Carthage/Carthage)*)

github "minacle/AAA" ~> 1.0


- **Podfile** (Using *[CocoaPods](https://cocoapods.org)*)
```ruby
target 'AWESOME_APP' do
  use_frameworks!
  pod 'AAA', '~> 1.0'
end

…Now, we have AAA. Let’s try it!

import AAA

func tion(_ anAny: Any) -> Int {
    let a = AAA(anAny)
    return (a[3][9][27][] ?? a["3"]["9"]["27"][]) as? Int ?? 0
}

Wait, what? Are these really same code? What a beautiful!

So, how to use it?

It’s super simple.

  1. Just wrap anything with AAA.
  2. Explore with index or key.
  3. [] to get a copy of the thing!

One more thing. It never throws error!

  • If index or key was wrong, it returns AAA which contains nil.
  • If so, [] returns nil.

Latest podspec

{
    "name": "AAA",
    "version": "1.0.6",
    "authors": {
        "Mayu Laierlence": "[email protected]"
    },
    "license": {
        "type": "MIT"
    },
    "homepage": "https://github.com/minacle/AAA",
    "source": {
        "git": "https://github.com/minacle/AAA.git",
        "tag": "v1.0.6"
    },
    "source_files": "Sources/**/*.swift",
    "summary": "An Any Accessory",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This