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