IOS基础笔记(一)

来源:互联网 发布:通达信软件公式函数 编辑:程序博客网 时间:2024/04/30 12:06

XCode是一种集成环境(IDE),文本编辑器。

编写代码也就需要编译器,连接器,调试等构成了IDE的核心。

编译器的功能:检查语法错误。

连接器:CRT ( c runtime ) 检查代码种的一些定义,声明等等 多了,少了什么。

调试器:找逻辑上的错误(设置断点,单步执行)。


Cocoa Touch: 基于移动开发的库的集合

IOS :移动设备的操作系统

Mac OS X:苹果PC设备的操作系统,开发工具的使用环境

.h:存放声明

.m:实现方法(函数)

@interface 用来定义类

@end代码类的结束


堆里的对象的一个类存单元,返回的就是类存单元的首地址

alloc 动态分配了一个类存

init 初始化

1、initWithFormat是实例办法

只能经由过程 NSString* str = [[NSString alloc] initWithFormat:@"%@",@"Hello World"] 调用,然则必须手动release来开释内存资料

2、stringWithFormat是类办法

可以直接用 NSString* str = [NSString stringWithFormat:@"%@",@"Hello World"] 调用,内存经管上是autorelease的,不消手动显式release

#import <Foundation/Foundation.h>@interface Student : NSObject{    NSString *name;    NSString *gender;    NSInteger age;}@end

#import "Student.h"@implementation Student-(id)init{    if (self=[super init]) {        name = @"Tom";        gender =@"male";        age=20;    }    return  self;}-(NSString *)description{    return [NSString stringWithFormat:@"name=%@,gender=%@,age=%ld",name,gender,age];}@end

#import <Foundation/Foundation.h>#import "Student.h"int main(int argc, const char * argv[]){    Student * stu1 = [[Student alloc] init];    NSLog(@"%@",stu1);    return 0;}

2014-12-10 21:14:59.870 OCText1[764:303] name=Tom,gender=male,age=20


////  Teacher.h//  OSHw1////  Created by Nesusoft on 14-12-10.//  Copyright (c) 2014年 IOS. All rights reserved.//#import <Foundation/Foundation.h>@class Student;@interface Teacher : NSObject{    NSString *name;    NSString *teach;        Student *student;}@end

////  Teacher.m//  OSHw1////  Created by Nesusoft on 14-12-10.//  Copyright (c) 2014年 IOS. All rights reserved.//#import "Teacher.h"#import "Student.h"@implementation Teacher-(id)init{    if (self=[super init]) {        name=@"Lidan";        teach=@"OCLanguege";        student =[[Student alloc]init];    }    return self;}-(NSString *)description{    return [NSString stringWithFormat:@"name=%@,tech=%@,student=%@",name,teach,student];}@end

////  Student.h//  OSHw1////  Created by Nesusoft on 14-12-10.//  Copyright (c) 2014年 IOS. All rights reserved.//#import <Foundation/Foundation.h>@interface Student : NSObject{    NSString *name;    NSString *gender;    NSInteger age;    NSInteger idCard;    NSInteger number;}-(void)hobby;@end

////  Student.m//  OSHw1////  Created by Nesusoft on 14-12-10.//  Copyright (c) 2014年 IOS. All rights reserved.//#import "Student.h"@implementation Student-(id)init{    if (self=[super init]) {        name=@"Jack";        gender=@"female";        age=20;        idCard=34123536;        number=1100;            }    return self;}-(NSString *)description{    return [NSString stringWithFormat:@"name=%@,gender=%@,age=%ld,id=%ld,number=%ld",name,gender,age,idCard,number];}-(void)hobby{    NSLog(@"self in hobby %p",self);    NSLog(@"play!!!");}@end

////  main.m//  OSHw1////  Created by Nesusoft on 14-12-10.//  Copyright (c) 2014年 IOS. All rights reserved.//#import <Foundation/Foundation.h>#import "Student.h"#import "Teacher.h"int main(int argc, const char * argv[]){    Student *stu=[[Student alloc]init];    NSLog(@"%@",stu);    NSLog(@"stu=%p®\n",stu);    [stu hobby];    Student *stu1=[[Student alloc]init];    NSLog(@"%@",stu1);    NSLog(@"stu1=%p®\n",stu1);    [stu1 hobby];    Teacher *teacher=[[Teacher alloc]init];    NSLog(@"%@\n",teacher);    return 0;}


0 0
原创粉丝点击