An Any Accessory.

What's New



Build environment:

  • Xcode 8.3.1 (8E1000a)
  • Apple Swift version 3.1 (swiftlang-802.0.51 clang-802.0.41)


  • Swift 3.1


  • Support OSX 10.9


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.

import PackageDescription

let package = Package(
    name: "AWESOME_APP",
    dependencies: [
        .Package(url: "", majorVersion: 1),
github "minacle/AAA" ~> 1.0
target 'AWESOME_APP' do
  pod 'AAA', '~> 1.0'

...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.


  • Swift Tools 3.1.0
View More Packages from this Author


  • None
Last updated: Fri Feb 03 2023 23:18:23 GMT-0500 (GMT-05:00)