• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to get the class name in Swift?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get the class name in Swift?


  • Subject: Re: How to get the class name in Swift?
  • From: Quincey Morris <email@hidden>
  • Date: Wed, 30 Jul 2014 00:59:54 -0700

On Jul 30, 2014, at 00:02 , Gerriet M. Denkmann <email@hidden> wrote:

How to translate this:
NSString *className = [ [ someObject class ] description ];
into Swift?

AFAICT, there isn’t any equivalent mechanism built into Swift yet. The two best answers I could find:

1. (from StackOverflow) Use NSStringFromClass (someObject.dynamicType), though this gives a mangled class name.

2. (from an example in the Swift book) Write a class method in each class you want to inspect, that returns a string literal for the readable class name. You can put the name of this method in a protocol to which each such class would conform.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to get the class name in Swift?
      • From: "Gerriet M. Denkmann" <email@hidden>
References: 
 >How to get the class name in Swift? (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Recognise classes between libraries
  • Next by Date: Re: How to get the class name in Swift?
  • Previous by thread: How to get the class name in Swift?
  • Next by thread: Re: How to get the class name in Swift?
  • Index(es):
    • Date
    • Thread