The sixth chapter object-oriented programming

Source: Internet
Author: User

This project is the "beginning iOS8 programming with Swift" project learning note = = "All Notes directory

--------------------------------------------------------------------------------------------------------------- ---

We used the resturantimages,Resturantnames and other member array variables to record restaurant information, the following we use an object-oriented approach to transform.
1. Create a resturant model class:

 class   Restaurant {var name  =  ""   var type  =   var location  =   var image  = 
     
       "" 
       var isvisited  = false   init (name:string, type:string, location:string, image:string, Isvisited:bool) {self.name  =
    
      name Self.type 
     = type self.location  = location self.image  = image self.isvisited  = isvisited}}  

2. Replace the previous string array member variable with an array of Resturant objects:

var restaurants =[Restaurant (Name:"Cafe deadend", type:"Coffee & Tea Shop", Location:"Hong Kong", Image:"cafedeadend.jpg", isvisited:false), Restaurant (name:"Homei", type:"Cafe", Location:"Hong Kong", Image:"homei.jpg", isvisited:false), Restaurant (name:"Teakha", type:"Tea House", Location:"Hong Kong", Image:"teakha.jpg", isvisited:false), Restaurant (name:"Cafe LOISL", type:"austrian/causual Drink", Location:"Hong Kong", Image:"cafeloisl.jpg", isvisited:false), Restaurant (name:"Petite Oyster", type:"French", Location:"Hong Kong", Image:"petiteoyster.jpg", isvisited:false), Restaurant (name:"For Kee Restaurant", type:"Bakery", Location:"Hong Kong", Image:"forkeerestaurant.jpg", isvisited:false), Restaurant (name:"Po ' s Atelier", type:"Bakery", Location:"Hong Kong", Image:"posatelier.jpg", isvisited:false), Restaurant (name:"Bourke Street backery", type:"Chocolate", Location:"Sydney", Image:"bourkestreetbakery.jpg", isvisited:false), Restaurant (name:"Haigh ' s chocolate", type:"Cafe", Location:"Sydney", Image:"haighschocolate.jpg", isvisited:false), Restaurant (name:"Palomino Espresso", type:"American/seafood", Location:"Sydney", Image:"palominoespresso.jpg", isvisited:false), Restaurant (name:"Upstate", type:"American", Location:"New York", Image:"upstate.jpg", isvisited:false), Restaurant (name:"Traif", type:"American", Location:"New York", Image:"traif.jpg", isvisited:false), Restaurant (name:"Graham Avenue Meats", type:"Breakfast & Brunch", Location:"New York", Image:"grahamavenuemeats.jpg", isvisited:false), Restaurant (name:"Waffle & Wolf", type:"Coffee & Tea", Location:"New York", Image:"wafflewolf.jpg", isvisited:false), Restaurant (name:"Five Leaves", type:"Coffee & Tea", Location:"New York", Image:"fiveleaves.jpg", isvisited:false), Restaurant (name:"Cafe Lore", type:"Latin American", Location:"New York", Image:"cafelore.jpg", isvisited:false), Restaurant (name:"Confessional", type:"Spanish", Location:"New York", Image:"confessional.jpg", isvisited:false), Restaurant (name:"Barrafina", type:"Spanish", Location:"London", Image:"barrafina.jpg", isvisited:false), Restaurant (name:"Donostia", type:"Spanish", Location:"London", Image:"donostia.jpg", isvisited:false), Restaurant (name:"Royal Oak", type:"British", Location:"London", Image:"royaloak.jpg", isvisited:false), Restaurant (name:"Thai Cafe", type:"Thai", Location:"London", Image:"thaicafe.jpg", isvisited:false)    ]

and modify the corresponding table to create the code, complete.

The sixth chapter object-oriented programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.