UI parts associated with StoryBoard

Asked 4 months ago, Updated 4 months ago, 10 views

The UI part (IBOutlet) linked from the StoryBoard will be of the ImplicitlyUnwrappedOptionsal type, but will it not become nil after the linked class is instantiated?

Migrating from Objective-C to Swift and
Until now, when I changed the frame of the associated UI part, I initialized it again as follows, assuming that it was nil, but I got an error with Swift.

self.titleLabel=UILabel (frame: CGRect (x:8, y:5, width:70, height:18))

If it does not become nil, I think I can handle it by changing only the value as below, but what do you think?

self.titleLabel.frame = CGRect (x:8, y:5, width:70, height:18)

swift xcode swift3

2022-09-30 14:23

1 Answers

API Reference-UIView-addSubview(_:)

Quote from this Discussion:

This method establishes a strong reference to view and sets next responder to the receiver, which is new superview.

Because Superview strongly references Subview, it does not become nil.This is the same with View deployments in Storyboard/Interface Builder.

*From Swift3, the ImplicitlyUnwrappedOptionsal type has been deprecated.

Abolish ImplicitlyUnwrappedOptionsal type

The type with ! is the Optional type with the Auto Unwrap option and is not different from the Optional type.


2022-09-30 14:23

If you have any answers or tips


© 2023 OneMinuteCode. All rights reserved.