Advertisement
Guest User

Properties

a guest
Apr 9th, 2020
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.60 KB | None | 0 0
  1. import Foundation
  2.  
  3. class Person{
  4.     var name = ""
  5. }
  6.  
  7. class BlogPost {
  8.  
  9.     var fullTitle:String{
  10.         if title != nil && author != nil {
  11.             return title! + " by " + author!.name
  12.         }
  13.         else{
  14.             return "No Title"
  15.         }
  16.     }
  17.  
  18.     var title:String?  //This is defined as NIL. The string is empty
  19.     var body:String = "Welcome"
  20.     var author:Person?  //empty
  21.     var numberOfComments:Int = 0
  22. }
  23.  
  24. let author = Person()
  25. author.name = "Shihab"
  26.  
  27. let myPost = BlogPost()
  28. myPost.author = author
  29. myPost.title = "Swift for beginners"
  30.  
  31. print(myPost.fullTitle)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement