博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第六章 面向对象编程
阅读量:7111 次
发布时间:2019-06-28

本文共 3379 字,大约阅读时间需要 11 分钟。

本项目是《beginning iOS8 programming with swift》中的项目学习笔记==》

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

前面我们用了resturantImages、resturantNames等成员数组变量记录餐馆信息,下面我们用面向对象的方法来改造。

1.    创建一个Resturant模型类:

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. 将之前的字符串数组成员变量替换为Resturant对象的数组:

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)    ]

并修改对应的表格创建代码,完成。

转载于:https://www.cnblogs.com/tangzhengyue/p/4307973.html

你可能感兴趣的文章
Windows7下的免费虚拟机(微软官方虚拟机)
查看>>
Linux下暴力破解工具Hydra详解
查看>>
Offer是否具有法律效力?
查看>>
Android SQLite系列
查看>>
怎么去掉li标签前面的点??
查看>>
Conjugate prior relationships
查看>>
深入Javascript中apply、call、bind
查看>>
.NET_Framework_version_history
查看>>
Android程序员必备精品资源
查看>>
Oracle SQL函数之转换函数To_char汇总
查看>>
Linux线程属性总结
查看>>
【原创】Kakfa log包源代码分析(二)
查看>>
Javascript 笔记与总结(2-16)事件对象
查看>>
[裴礼文数学分析中的典型问题与方法习题参考解答]4.4.7
查看>>
JAVA存取对象属性时,如果开程多线程,记得对相关存取方法作原子化操作定义...
查看>>
深度学习 vs. 概率图模型 vs. 逻辑学
查看>>
Eclipse中使用javap运行配置详解
查看>>
DHCP租约时间工作原理
查看>>
Qt移动应用开发(六):QML与C++互动
查看>>
svn代码统计工具的金额
查看>>