Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document a struct within a struct in XCode (Swift or Obj-C)

We all know that when documenting a struct, you can use @struct for your struct and use @field to explains the content within the struct.

But how to document a struct with some fields that is within another struct?

In Swift, the example code will be:

struct Constants{
    static let kButtonHeight : CGFloat = 0
    struct Color {
      static let kCloud: UIColor = UIColor(red: 236/255, green: 240/255, blue: 241/255, alpha: 1.0)
    }
}

Thank you so much!

like image 623
donkey Avatar asked Feb 04 '26 05:02

donkey


1 Answers

If you're doing this in Swift, you can prefix anything (type, property, or instance, etc.) with either single-line comments marked by /// or multi-line comments beginning with /**. So your documentation could simply be:

/// A global container for all constants
struct Constants{
    /// The default button height
    static let kButtonHeight : CGFloat = 0

    /// Constant UIColor instances for my app
    struct Color {
        /// The cloud color - a very pale blue-white
        static let kCloud: UIColor = UIColor(red: 236/255, green: 240/255, blue: 241/255, alpha: 1.0)
    }
}

The documentation attaches immediately -- option click on a name and you get the relevant documentation:

enter image description here

like image 200
Nate Cook Avatar answered Feb 06 '26 21:02

Nate Cook



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!