iOS7 Introduction

####iOS7 Programming Cookbook 第一章学习笔记 Introduction

#####Demo:Chapter 1-Introduction

######AppDelegate.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
//声明一组,可变无序对象的集合
NSCountedSet *setOfNumbers = [NSCountedSet setWithObjects:
@10, @20, @10, @10, @30, nil];
//添加20
[setOfNumbers addObject:@20];
//移除10
[setOfNumbers removeObject:@10];

NSLog(@"Count for object @10 = %lu",(unsigned long)[setOfNumbers countForObject:@10]);
//2013-12-23 21:44:41.339 Chapter 1-Introduction[1683:70b] Count for object @10 = 2

NSLog(@"Count for object @20 = %lu",(unsigned long)[setOfNumbers countForObject:@20]);
//2013-12-23 21:44:41.339 Chapter 1-Introduction[1683:70b] Count for object @20 = 2


self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

return YES;
}

######Car.h

1
2
3
4
5
6
7
8
9

@protocol Car <NSObject>//协议

//协议的变量声明
@property (nonatomic, copy) NSArray *wheels;
@property (nonatomic, strong) UIColor *bodyColor;
@property (nonatomic, copy) NSArray *doors;

@end

######Jaguar.h

1
2
3
4
5
6
7
@interface Jaguar : NSObject <Car>//添加Car的协议

@property (nonatomic, copy) NSArray *wheels;
@property (nonatomic, strong) UIColor *bodyColor;
@property (nonatomic, copy) NSArray *doors;

@end

######Person.h

1
2
3
4
5
6
7
8
9
10
11
12
13
@interface Person : NSObject

//声明公开变量
@property (nonatomic, copy) NSString *firstName;
@property (nonatomic, copy) NSString *lastName;
//所有浮点值的基本类型
@property (nonatomic, assign) CGFloat currentHeight;

//类方法
+ (CGFloat) maximumHeightInCentimeters;
+ (CGFloat) minimumHeightInCentimeters;

@end

Reference

坚持原创技术分享,您的支持将鼓励我继续创作!
0%