Skip to content
This repository was archived by the owner on Jan 6, 2020. It is now read-only.

Repository files navigation

AnyObjectConvertible

Build StatusCarthage compatibleCocoaPods compatible

Convert your own struct/enum to AnyObject easily.

Sumally

We can cast everything as AnyObject at Swift3.0 🎉
So, we would not need this library no longer

In swift, struct or enum cannot convert to AnyObject

NSNotificationCenter.defaultCenter().postNotificationName("foo", object:YourOwnStruct()) // Fail

Of course, you may wrap value using Box<T>.

classBox<T>{letvalue:Tinit(value:T){self.value = value
}}NSNotificationCenter.defaultCenter().postNotificationName("foo", object:Box(value:YourOwnStruct())) // OK

But Box<T> unwrap is too lazy.

letvalue=(notification.object as?Box<YourOwnStruct>)?.value

You can cast your struct/enum directory if implement AnyObjectConvertible at that type.

extensionYourOwnStruct:AnyObjectConvertible{}NSNotificationCenter.defaultCenter().postNotificationName("foo", object:YourOwnStruct()) // OK
letvalue= notification.object as?YourOwnStruct

Installation

CocoaPods

You can use CocoaPods to install AnyObjectConvertible by adding it to your Podfile:

platform:ios,'8.0'use_frameworks!pod'AnyObjectConvertible'

To get the full benefits import AnyObjectConvertible wherever you import UIKit

import UIKit
import AnyObjectConvertible

Carthage

Create a Cartfile that lists the framework and run carthage bootstrap. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/YourLibrary.framework to an iOS project.

github "tarunon/AnyObjectConvertible"

Manually

  1. Download and drop AnyObjectConvertible.swift in your project.
  2. Congratulations!

License

MIT

About

Convert your own struct/enum to AnyObject easily.

Resources

Stars

60 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages