美文网首页
OC-错误分析

OC-错误分析

作者: 孙国庆 | 来源:发表于2015-05-28 19:33 被阅读51次

// main.m
// 03-错误分析
//
// Created by sunguoqing on 15/4/29.
// Copyright (c) 2015年 sunguoqing. All rights reserved.
//

import <Foundation/Foundation.h>

//人

//声明
//@interface Person : NSObject
////属性,方法的声明
//{
// int _age;
//}
//
//-(void)run;
//
//@end
//实现

@implementation Person : NSObject
{
int _age;
}

-(void)run{
NSLog(@"我在跑");
}

@end

int main(int argc, const char * argv[])
{

@autoreleasepool {
    
    Person *person = [Person new];
    
    [person run];
    
    
    /**
     常见错误分析
     1.只写声明,不写实现
     2.忘写@end
     3.声明与实现不能嵌套,也不允许与函数嵌套
     4.在声明当中,属性必须写在{}里面
     5.方法的声明必须放在{}后面
     6.不能声明当中直接给属性赋值
     7.方法不能只写声明不写实现,会报经典错误
     '-[Person run]: unrecognized selector sent to instance 0x100306840'翻译:没有找到当前调用的方法
     8.忘了写:NSObject
     9.只写类的实现,不写声明
     可以实现,但是这是oc的弱语法,不推荐使用
     */
    
}
return 0;

}

相关文章

网友评论

      本文标题:OC-错误分析

      本文链接:https://www.haomeiwen.com/subject/tvirqttx.html