Convert your own struct/enum to AnyObject easily.

Overview

AnyObjectConvertible

Build Status Carthage compatible CocoaPods 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>.

class Box<T> {
  let value: T
  init(value: T) {
    self.value = value
  }
}
NSNotificationCenter.defaultCenter().postNotificationName("foo", object: Box(value: YourOwnStruct())) // OK

But Box<T> unwrap is too lazy.

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

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

extension YourOwnStruct: AnyObjectConvertible {}

NSNotificationCenter.defaultCenter().postNotificationName("foo", object: YourOwnStruct()) // OK
let value = 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

You might also like...
A simple class that wraps the process of saving or loading a struct or class into a single file

EZFile This is a simple class that wraps the process of saving or loading a stru

SFSymbols SwiftUI Enum
SFSymbols SwiftUI Enum

SF SFSymbols SwiftUI Enum Example: All lines are equivalent. Image(systemName: "square.fill.and.line.vertical.square.fill") Image(systemName:

Create your own faces for watchOS.  Customize the watch hands, layout, colors, and images.  Edit faces on your phone and switch them on the watch.
Create your own faces for watchOS. Customize the watch hands, layout, colors, and images. Edit faces on your phone and switch them on the watch.

AppleWatchFaces Design your own watch faces for the apple watch. They are not real watch faces, but a watchOS app running on the watch that tells you

PJAlertView - This library is to make your own custom alert views to match your apps look and feel

PJAlertView - This library is to make your own custom alert views to match your apps look and feel

A pure Swift library that allows you to easily convert SwiftUI Colors to Hex String and vice versa.
A pure Swift library that allows you to easily convert SwiftUI Colors to Hex String and vice versa.

iOS ยท macOS ยท watchOS ยท tvOS A pure Swift library that allows you to easily convert SwiftUI Colors to Hex String and vice versa. There is also support

Create an easy to peek SwiftUI View to showcase your own data, catalog, images, or anything you'd like.
Create an easy to peek SwiftUI View to showcase your own data, catalog, images, or anything you'd like.

Create an easy to peek SwiftUI View to showcase your own data, catalog, images, or anything you'd like.

Repository with base samples for playing HLS/DASH with CMAF video, across as many platforms as possible. Includes steps for encoding and packaging your own test content.

Video Everything Repository with minimal samples for playing HLS/DASH with CMAF video, across as many platforms as possible. Content and License All t

Build your own 'AirTags' ๐Ÿท today! Framework for tracking personal Bluetooth devices via Apple's massive Find My network.
Build your own 'AirTags' ๐Ÿท today! Framework for tracking personal Bluetooth devices via Apple's massive Find My network.

OpenHaystack is a framework for tracking personal Bluetooth devices via Apple's massive Find My network.

Demonstrate a way to build your own line chart without using any third-party library
Demonstrate a way to build your own line chart without using any third-party library

LineChart This code demonstrate a way to build your own line chart without using any third-party library. It contains a simple yet effective algorithm

An iOS app to turn typed text into images of handwritten text in your own handwriting style.
An iOS app to turn typed text into images of handwritten text in your own handwriting style.

Text-to-Handwritting ยฉ 2021 by Daniel Christopher Long An iOS app to turn typed text into images of handwritten text in your own handwriting style. ht

PowerUp is an educational choose-your-own-adventure game that utilizes a users uploaded curriculum to empower pre-adolescents to take charge of their reproductive health.

PowerUp is an educational choose-your-own-adventure game that utilizes a users uploaded curriculum to empower pre-adolescents to take charge of their reproductive health. This is the iOS version of the game.

iOS client for the Brewfactory project - brew your own beer
iOS client for the Brewfactory project - brew your own beer

BrewMobile iOS client for the Brewfactory project. Read the stories of upgrading BrewMobile to ReactiveCocoa & Swift on AllTheFlow. What is this? App

ButtonClickStyle - This is a Customizable/Designable Button View, with 15 animated click styles, that allows you to design your own buttons from subviews, in storyboard and xib right away.
ButtonClickStyle - This is a Customizable/Designable Button View, with 15 animated click styles, that allows you to design your own buttons from subviews, in storyboard and xib right away.

ButtonClickStyle - This is a Customizable/Designable Button View, with 15 animated click styles, that allows you to design your own buttons from subviews, in storyboard and xib right away.

๐Ÿ“ฑ A simple wallpaper editor application for iPhone. Create your own wallpapers with a beautiful shelves.
๐Ÿ“ฑ A simple wallpaper editor application for iPhone. Create your own wallpapers with a beautiful shelves.

iShelf A simple wallpaper editor application for iPhone. Create your own wallpapers with a beautiful shelves. ๐ŸŽจ Demo ๐Ÿ“ธ Screenshots โœจ Features Lots o

๐Ÿ“ก Helping you own NotificationCenter in Swift!

Notificationz ๐Ÿ“ก Helping you own NotificationCenter Highlights Keep Your Naming Conventions: This library gives you convenient access to NotificationC

Cluster's reusable pre-permissions utility that lets developers ask the users on their own dialog for photos or contacts access, before making the system-based request.
Cluster's reusable pre-permissions utility that lets developers ask the users on their own dialog for photos or contacts access, before making the system-based request.

Cluster's reusable pre-permissions utility that lets developers ask the users on their own dialog for photos or contacts access, before making the system-based request. This is based on the Medium post by Cluster describing the different ways to ask for iOS permissions (https://medium.com/p/96fa4eb54f2c).

Try to create my own DI container
Try to create my own DI container

Basic Dependecy Injection Simple solution for DI Dependecy registration Registration strong dependency Registration weak dependency Registration with

๐Ÿ“ก Helping you own NotificationCenter in Swift!

Notificationz ๐Ÿ“ก Helping you own NotificationCenter Highlights Keep Your Naming Conventions: This library gives you convenient access to NotificationC

Releases(0.0.3)
Owner
tarunon
Swift slug
tarunon
Monaka convert custom struct to NSData.

Monaka Overview Monaka convert custom struct and fundamental values to NSData (also nested array and dictionary). Purpose You can persistent store of

Naruki Chigira 22 Oct 29, 2020
๐Ÿ’ป LeetCode in your menu bar

LeetBar LeetCode in your menu bar Features Check the daily problem and view profile stats from your menu bar Get notified about the new daily problem

Marwan Hawari 45 Dec 18, 2022
JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift.

JSEN /หˆdส’eษชsษ™n/ JAY-sษ™n JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift. A JSON, as defined in the EC

Roger Oba 8 Nov 22, 2022
RandMyMod base on your own struct or class create one or a set of instance, which the variable's value in the instance is automatic randomized.

RandMyMod is an IOS Native Framework helps you generate one or a set of variable base on your own model. No matter your model is Class / Struct. Insta

้ƒญไป‹้จต 17 Sep 24, 2022
Monaka convert custom struct to NSData.

Monaka Overview Monaka convert custom struct and fundamental values to NSData (also nested array and dictionary). Purpose You can persistent store of

Naruki Chigira 22 Oct 29, 2020
CachyKit - A Caching Library is written in Swift that can cache JSON, Image, Zip or AnyObject with expiry date/TTYL and force refresh.

Nice threadsafe expirable cache management that can cache any object. Supports fetching from server, single object expire date, UIImageView loading etc.

Sadman Samee 122 Dec 28, 2022
NotificationCenter based Lightweight UI / AnyObject binder.

Continuum NotificationCenter based Lightweight UI / AnyObject binder. final class ViewController: UIViewController { @IBOutlet weak var label: UI

Taiki Suzuki 82 Apr 4, 2021
๐Ÿ”Œ Enum key paths

?? Enum key paths With the package you can use key paths with enums import EnumKeyPaths

Incetro 10 Mar 23, 2022
A protocol that allows any class to be printed as if it were a struct or a JSON object.

ReflectedStringConvertible A protocol that extends CustomStringConvertible and uses reflection to add a detailed textual representation to any class.

Matt Comi 65 Dec 24, 2022
Parsing indeterminate types with Decodable and Either enum using Swift

Decodable + Either Parsing indeterminate types with Decodable and Either enum us

Alonso Alvarez 1 Jan 9, 2022