一个星期学习objective-c移动开发第二天笔记

来源:互联网 发布:游族网络怎么样 编辑:程序博客网 时间:2024/05/16 17:41

第一天:讲理论,略。

第二天:主要学习 类 、 对象 并在 xcode编程中的使用。

1、类: 是一组具有相同特征和行为的对象的集合。

2、对象: 是类的实例化。

3、 对象和类的区别: 对象是特定的某个事物,累是泛指一批事物。

4、创建一个student类:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
main.m
 #import <Foundation/Foundation.h>
 #import "Student.h"
 int main (int argc,const char * argv[ ] )
{
 @autoreleasepool{
 student * stu1= [[Student alloc] init ];   //alloc动态分配内存
 stu1->name=@"kevin";
 stu1->sex=@"male";
 stu1->number=19;
 stu1->age=12;
 NSLog(@"我叫%@,性别是%@,我的学号是%d,我的年龄是%d,",stu1->name,stu1->sex,stu1->number,stu1->age);
 }
 return 0;
}
  
 student.h
  
#import<Foundation/Foundation.h>
 @interface student: NSObject
 {
 NSString * name;    //姓名
 NSSring * sex;         //性别
 init age;             //年龄
 int number;          //学号
 }
 -(void)study;
 @end
  
 student.m
 #import "student.h"
 @implementation Student
 +(void)eat{
 NSLog(@"我每天12点吃饭");    //+开头:类方法
 }
 -(void)study{
 NSLog(@“我是学生,我每天8点上课”);
 }
 @end