IOS设计模式之一(MVC模式,单例模式)

- @property (nonatomic, copy, readonly) NSString *title, *artist, *genre, *coverUrl, *year;
- - (id)initWithTitle:(NSString*)title artist:(NSString*)artist coverUrl:(NSString*)coverUrl year:(NSString*)year;
- - (id)initWithTitle:(NSString*)title artist:(NSString*)artist coverUrl:(NSString*)coverUrl
- year:(NSString*)year {
- self = [super init];
- if (self)
- {
- _title = title;
- _artist = artist;
- _coverUrl = coverUrl;
- _year = year;
- _genre = @"Pop";
- }
- return self;
- }
- - (id)initWithFrame:(CGRect)frame albumCover:(NSString*)albumCover;
- @implementationAlbumView
- {
- UIImageView *coverImage;
- UIActivityIndicatorView *indicator;
- }
- - (id)initWithFrame:(CGRect)frame albumCover:(NSString*)albumCover
- {
- self = [super initWithFrame:frame];
- if (self)
- {
- self.backgroundColor = [UIColor blackColor];
- // the coverImage has a 5 pixels margin from its frame
- coverImage = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, frame.size.width-10,
- frame.size.height-10)];
- [self addSubview:coverImage];
- indicator = [[UIActivityIndicatorView alloc] init];
- indicator.center = self.center;
- indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
- [indicator startAnimating];
- [self addSubview:indicator];
- }
- return self;
- }
- @end




- @interfaceLibraryAPI : NSObject
- + (LibraryAPI*)sharedInstance;
- @end
- + (LibraryAPI*)sharedInstance
- {
- // 1
- static LibraryAPI *_sharedInstance = nil;
- // 2
- static dispatch_once_t oncePredicate;
- // 3
- dispatch_once(&oncePredicate, ^{
- _sharedInstance = [[LibraryAPI alloc] init];
- });
- return _sharedInstance;
- }
- - (NSArray*)getAlbums;
- - (void)addAlbum:(Album*)album atIndex:(int)index;
- - (void)deleteAlbumAtIndex:(int)index;
- @interfacePersistencyManager () {
- // an array of all albums
- NSMutableArray *albums;
- }
- - (id)init
- {
- self = [super init];
- if (self) {
- // a dummy list of albums
- albums = [NSMutableArrayarrayWithArray:
- @[[[Album alloc] initWithTitle:@"Best of Bowie" artist:@"David Bowie" coverUrl:@"http://www.coversproject.com/static/thumbs/album/album_david%20bowie_best%20of%20bowie.png" year:@"1992"],
- [[Album alloc] initWithTitle:@"It's My Life" artist:@"No Doubt" coverUrl:@"http://www.coversproject.com/static/thumbs/album/album_no%20doubt_its%20my%20life%20%20bathwater.png" year:@"2003"],
- [[Album alloc] initWithTitle:@"Nothing Like The Sun" artist:@"Sting" coverUrl:@"http://www.coversproject.com/static/thumbs/album/album_sting_nothing%20like%20the%20sun.png" year:@"1999"],
- [[Album alloc] initWithTitle:@"Staring at the Sun" artist:@"U2" coverUrl:@"http://www.coversproject.com/static/thumbs/album/album_u2_staring%20at%20the%20sun.png" year:@"2000"],
- [[Album alloc] initWithTitle:@"American Pie" artist:@"Madonna" coverUrl:@"http://www.coversproject.com/static/thumbs/album/album_madonna_american%20pie.png" year:@"2000"]]];
- }
- return self;
- }
- - (NSArray*)getAlbums
- {
- return albums;
- }
- - (void)addAlbum:(Album*)album atIndex:(int)index
- {
- if (albums.count >= index)
- [albums insertObject:album atIndex:index];
- else
- [albums addObject:album];
- }
- - (void)deleteAlbumAtIndex:(int)index
- {
- [albums removeObjectAtIndex:index];
- }
IOS设计模式之一(MVC模式,单例模式)的更多相关文章
- iOS 设计模式之工厂模式
iOS 设计模式之工厂模式 分类: 设计模式2014-02-10 18:05 11020人阅读 评论(2) 收藏 举报 ios设计模式 工厂模式我的理解是:他就是为了创建对象的 创建对象的时候,我们一 ...
- Android 设计模式之MVC模式
说到Android设计模式的MVC模式,估计很多人都是比较熟悉了,这里深入了解一下MVC到底是怎么回事,以ListView为例子讲解. 一.深入理解MVC概念 MVC即Model-View-Contr ...
- python 设计模式之MVC模式
一.简单介绍 mvc模式 the model-view-controller pattern mvc模式是一个运用在软件工程中的设计模式.mvc模式脱离了以前简单的web服务设计逻辑,将开发,测试 ...
- Python设计模式之MVC模式
# -*- coding: utf-8 -*- # author:baoshan quotes = ('A man is not complete until he is married. Then ...
- iOS:使用MVC模式帮ViewController瘦身
如何给UIViewController瘦身 随着程序逻辑复杂度的提高,你是否也发现了App中一些ViewController的代码行数急剧增多,达到了2,3千行,甚至更多.这时如果想再添加一点功能或者 ...
- 设计模式-14 MVC模式
一 MVC设计模式 MVC 模式代表 Model-View-Controller(模型-视图-控制器) 模式,它是一个存在于服务器 表达层的模型,它将应用分开,改变应用之间的高度耦合 MVC设计模式将 ...
- 【设计模式】MVC模式
MVC 模式代表 Model-View-Controller(模型-视图-控制器) 模式.这种模式用于应用程序的分层开发. Model(模型) - 模型代表一个存取数据的对象或 JAVA POJO.它 ...
- python的设计模式之MVC模式
模型-视图-控制器模式 关注点分离(Separation of Concerns,SoC)原则是软件工程相关的设计原则之一.SoC原则背后的思想是将一个应用切分成不同的部分,每个部分解决一个单独的关注 ...
- iOS架构入门 - MVC模式实例演示
MVC模式的目的是实现一种动态的程序设计,使后续对程序的修改和扩展简化,并且使程序某一部分的重复利用成为可能.除此之外,此模式通过对复杂度的简化,使程序结构更加直观 控制器(Controller)-- ...
- iOS通用的MVC模式项目框架MobileProject
最近项目比较不赶的情况下,决定把一些通用.常用的内容集成在一个项目框架中,意在新项目中可以快速搭建:其实经过几个项目后,总是有一些重复的创建工作,可以使用本项目的内容直接进行开发:采用的是MVC的分层 ...
随机推荐
- python函数传参是传值还是传引用?
首先还是应该科普下函数参数传递机制,传值和传引用是什么意思? 函数参数传递机制问题在本质上是调用函数(过程)和被调用函数(过程)在调用发生时进行通信的方法问题.基本的参数传递机制有两种:值传递和引用传 ...
- Mysql 注意细节
1.无法连接远程数据库,是因为远程服务器并没有开通权限,提供给其他机子连接: 在服务器机子 开通权限: 1)进去MySql 2)mysql>GRANT ALL PRIVILEGES ...
- Reporting Service报表项默认可见+号和-号的显示问题
在Reporting Service里面可以设置报表项(组.tablix行.tablix列.文本框等所有SSRS报表项)的可见性,并且可以设置某个报表项的可见性由点击另外一个报表项来控制,比如报表项A ...
- SQL SERVER2000中订阅与发布的具体操作
同步过程 一.准备工作,如果完成则可跳过. 1.内网DB服务器作为发布服务器,外网DB服务器作为订阅服务器. 发布服务器和订阅服务器上分别创建Windows用户jl,密码jl,隶属于administr ...
- web跨页弹窗选值
最近在项目中看到这样一种效果——点击当前网页文本框,然后弹出一个缩小的网页,并在网页里选择或填写数据,然后又返回当前网页,小网页关闭.感觉非常不错,其实在以前网上也看见过,只是当时没有留心.今天抽时间 ...
- python实现指定目录下批量文件的单词计数:串行版本
直接上代码. 练习目标: 1. 使用 Python 面向对象的方法封装逻辑和表达 : 2. 使用异常处理和日志API : 3. 使用文件目录读写API : 4. 使用 list, map, t ...
- protocolbuffe
protocolbuffer(以下简称PB)是google 的一种数据交换的格式,它独立于语言,独立于平台.google 提供了多种语言的实现:java.c#.c++.go 和 python,每一种实 ...
- 【python cookbook】【数据结构与算法】2 从任意长度的可迭代对象中分解元素
从某个可迭代对象中分解出N个元素,但是可迭代对象的长度可能超过N,会出现“分解值过多”的异常: 使用“*表达式”来解决该问题: Python 3.4.3 (v3.4.3:9b73f1c3e601, F ...
- jython学习笔记3
1.os.environ["HOME"] 为什么这句话在我的STS中打印不出东西,还报错 Method Description close() Close file fileno( ...
- diff 文件比较
测试数据: [xiluhua@vm-xiluhua][~]$ cat msn.txt aaa bbb bbb ccc ccc ddd bbb eee aaa ccc bbb sss [xiluhua@ ...