Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

complete list of @IB* in xcode and their use cases

Tags:

xcode

ios

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?

like image 336
Thor Avatar asked Aug 09 '17 00:08

Thor


Video Answer


1 Answers

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):

@IBAction

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)

@IBOutlet

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!

@IBOutletColection (now it's just [] of @IBOutlet!)

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

@IBDesignable

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.

@IBinspectable

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: enter image description here


There is also some other like: @GKInspectable, @NSManaged,@nonobjc , @available and so on... You can read more about attributes in swift here

like image 133
Jakub Avatar answered Nov 16 '22 10:11

Jakub