Swift Syntax for Objective C [closed]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















In Obj C I created a property



@property(nonatomic) UILabel *subscriptionText;


Then I created a setter method for that property UILabel. like below



-(UILabel *)subscriptionText{
if (!_subscriptionText) {
_subscriptionText = [UILabel new];
_subscriptionText.translatesAutoresizingMaskIntoConstraints = NO;
_subscriptionText.textAlignment = NSTextAlignmentJustified;


}
return _subscriptionText;
}


then In viewdidload I add this view by



[self.view addSubview:self.subscriptionText];


How can I do this same scenario in Swift 4.2.










share|improve this question















closed as too broad by matt, Gereon, Hardik Thakkar, vikingosegundo, rmaddy Nov 17 '18 at 16:14


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 2





    -(UILabel *)subscriptionText; is a getter method.

    – Badhan Ganesh
    Nov 17 '18 at 7:11













  • In Swift Bro I am Asking

    – Ruban4Axis
    Nov 17 '18 at 7:15


















1















In Obj C I created a property



@property(nonatomic) UILabel *subscriptionText;


Then I created a setter method for that property UILabel. like below



-(UILabel *)subscriptionText{
if (!_subscriptionText) {
_subscriptionText = [UILabel new];
_subscriptionText.translatesAutoresizingMaskIntoConstraints = NO;
_subscriptionText.textAlignment = NSTextAlignmentJustified;


}
return _subscriptionText;
}


then In viewdidload I add this view by



[self.view addSubview:self.subscriptionText];


How can I do this same scenario in Swift 4.2.










share|improve this question















closed as too broad by matt, Gereon, Hardik Thakkar, vikingosegundo, rmaddy Nov 17 '18 at 16:14


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 2





    -(UILabel *)subscriptionText; is a getter method.

    – Badhan Ganesh
    Nov 17 '18 at 7:11













  • In Swift Bro I am Asking

    – Ruban4Axis
    Nov 17 '18 at 7:15














1












1








1








In Obj C I created a property



@property(nonatomic) UILabel *subscriptionText;


Then I created a setter method for that property UILabel. like below



-(UILabel *)subscriptionText{
if (!_subscriptionText) {
_subscriptionText = [UILabel new];
_subscriptionText.translatesAutoresizingMaskIntoConstraints = NO;
_subscriptionText.textAlignment = NSTextAlignmentJustified;


}
return _subscriptionText;
}


then In viewdidload I add this view by



[self.view addSubview:self.subscriptionText];


How can I do this same scenario in Swift 4.2.










share|improve this question
















In Obj C I created a property



@property(nonatomic) UILabel *subscriptionText;


Then I created a setter method for that property UILabel. like below



-(UILabel *)subscriptionText{
if (!_subscriptionText) {
_subscriptionText = [UILabel new];
_subscriptionText.translatesAutoresizingMaskIntoConstraints = NO;
_subscriptionText.textAlignment = NSTextAlignmentJustified;


}
return _subscriptionText;
}


then In viewdidload I add this view by



[self.view addSubview:self.subscriptionText];


How can I do this same scenario in Swift 4.2.







ios objective-c swift






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 3:36







Ruban4Axis

















asked Nov 17 '18 at 6:38









Ruban4AxisRuban4Axis

348114




348114




closed as too broad by matt, Gereon, Hardik Thakkar, vikingosegundo, rmaddy Nov 17 '18 at 16:14


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as too broad by matt, Gereon, Hardik Thakkar, vikingosegundo, rmaddy Nov 17 '18 at 16:14


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 2





    -(UILabel *)subscriptionText; is a getter method.

    – Badhan Ganesh
    Nov 17 '18 at 7:11













  • In Swift Bro I am Asking

    – Ruban4Axis
    Nov 17 '18 at 7:15














  • 2





    -(UILabel *)subscriptionText; is a getter method.

    – Badhan Ganesh
    Nov 17 '18 at 7:11













  • In Swift Bro I am Asking

    – Ruban4Axis
    Nov 17 '18 at 7:15








2




2





-(UILabel *)subscriptionText; is a getter method.

– Badhan Ganesh
Nov 17 '18 at 7:11







-(UILabel *)subscriptionText; is a getter method.

– Badhan Ganesh
Nov 17 '18 at 7:11















In Swift Bro I am Asking

– Ruban4Axis
Nov 17 '18 at 7:15





In Swift Bro I am Asking

– Ruban4Axis
Nov 17 '18 at 7:15












1 Answer
1






active

oldest

votes


















9














A lazy initialization is what you need.



lazy var subscriptionText: UILabel = {
let label = UILabel()
label.textAlignment = .justified

label.translatesAutoresizingMaskIntoConstraints = false
return label
}()

func viewDidLoad() {
super.viewDidLoad()

view.addSubview(subscriptionLabel)

// Label constraints
}





share|improve this answer
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    9














    A lazy initialization is what you need.



    lazy var subscriptionText: UILabel = {
    let label = UILabel()
    label.textAlignment = .justified

    label.translatesAutoresizingMaskIntoConstraints = false
    return label
    }()

    func viewDidLoad() {
    super.viewDidLoad()

    view.addSubview(subscriptionLabel)

    // Label constraints
    }





    share|improve this answer






























      9














      A lazy initialization is what you need.



      lazy var subscriptionText: UILabel = {
      let label = UILabel()
      label.textAlignment = .justified

      label.translatesAutoresizingMaskIntoConstraints = false
      return label
      }()

      func viewDidLoad() {
      super.viewDidLoad()

      view.addSubview(subscriptionLabel)

      // Label constraints
      }





      share|improve this answer




























        9












        9








        9







        A lazy initialization is what you need.



        lazy var subscriptionText: UILabel = {
        let label = UILabel()
        label.textAlignment = .justified

        label.translatesAutoresizingMaskIntoConstraints = false
        return label
        }()

        func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(subscriptionLabel)

        // Label constraints
        }





        share|improve this answer















        A lazy initialization is what you need.



        lazy var subscriptionText: UILabel = {
        let label = UILabel()
        label.textAlignment = .justified

        label.translatesAutoresizingMaskIntoConstraints = false
        return label
        }()

        func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(subscriptionLabel)

        // Label constraints
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 17 '18 at 9:57

























        answered Nov 17 '18 at 7:24









        Rakesha ShastriRakesha Shastri

        7,78121735




        7,78121735

















            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python