I'm currently learning iOS development in swift
.
In xcode, I know the most commonly used @IB
are @IBAction
and @IBOutlet
, there are other @IB
such as @IBInspectable
, @IBDesignable
.
But I was wondering, Is there other @IB
available and what is their use cases?
Those are attibutes, and AFAIK There is a no complete list from Apple, but there is an IDE
test file in swift repository, that gather in test all this data for IB
prefix (probably stands for Interface Builder
):
https://developer.apple.com/documentation/appkit/constants/interface_builder_constants/ibaction
Type qualifier used by Interface Builder to expose a method as a connection point between user interface elements and app code. Used instead of a void return type in a method declaration. For examples of how to use this identifier, see Xcode Overview.
In other words - it's connect your storyboard object like UIButton
to action that can be performed on it @IBAction func didTap(_ sender: Any)
https://developer.apple.com/documentation/appkit/constants/interface_builder_constants/iboutlet?language=objc
Type qualifier used by Interface Builder to expose a symbol as a connection point for sending messages from app code to a user interface element. Used immediately before an object type in a property or instance variable declaration. For examples of how to use this identifier, see Xcode Overview.
In other words - it's something to refer to when you want to change (ex) text in label. @IBOutlet weak var label: UILabel!
Whenever group of outlets, should have similar (or better - the same!) behaviour and styling you can put it all together under @IBOutletCollection
. It looks like this: @IBOutlet var someLabels: [UILabel]!
Both below help with live rendering:
You can use two different attributes—@IBDesignable and @IBInspectable—to enable live, interactive custom view design in Interface Builder. When you create a custom view that inherits from the UIView class or the NSView class
You can add the @IBDesignable attribute just before the class declaration. After you add the custom view to Interface Builder (by setting the custom class of the view in the inspector pane), Interface Builder renders your view in the canvas.
You can also add the @IBInspectable attribute to properties with types compatible with user defined runtime attributes. After you add your custom view to Interface Builder, you can edit these properties in the inspector.
More information you can find here
It look in Interface Builder like this:
There is also some other like: @GKInspectable
, @NSManaged
,@nonobjc
, @available
and so on... You can read more about attributes in swift here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With