Skip to content

A simple function for getting the name of the non optional type in Swift.

License

Notifications You must be signed in to change notification settings

vadymmarkov/TypeHelper

Repository files navigation

TypeHelper

Version License Platform

A simple function for getting the name of the non optional type in Swift (from optional or implicitly unwrapped optional types).

Usage

  let some: SomeClass = SomeClass()
  let someOptional: SomeClass? = SomeClass()
  let someImplicitlyUnwrappedOptional: SomeClass! = SomeClass()

  println(nonOptionalTypeName(some.dynamicType)) // <namespace>.SomeClass
  println(nonOptionalTypeName(someOptional.dynamicType)) // <namespace>.SomeClass
  println(nonOptionalTypeName(someImplicitlyUnwrappedOptional.dynamicType)) // <namespace>.SomeClass

  println(nonOptionalTypeName(Printable)) // Swift.Printable
  println(nonOptionalTypeName(Printable?)) // Swift.Printable

  println(nonOptionalTypeName(UIView)) // UIView
  println(nonOptionalTypeName(UIView?)) // UIView

Installation

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

pod 'TypeHelper'

Author

Vadym Markov, impressionwave@gmail.com

License

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

About

A simple function for getting the name of the non optional type in Swift.

Resources

License

Stars

Watchers

Forks

Packages

No packages published