黑马程序员技术交流社区

标题: 第一次写oc代码遇到问题了报错了,不知道为什么,跟视频一样的内容 [打印本页]

作者: lyricdon    时间: 2015-4-24 14:14
标题: 第一次写oc代码遇到问题了报错了,不知道为什么,跟视频一样的内容
//
//  main.m
//  basic1.1
//
//  Created by lyricdon on 15/4/24.
//  Copyright (c) 2015年 lyricdon. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Dog.h"
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        NSLog(@"Hello, World!");
        
        Dog *dog1=[Dog alloc];
        [dog1 init];
            
        int ID=[dog1 getID];
        int age=[dog1 getAge];
        float price=[dog1 getPrice];
        
        printf("dog1 id is %d age is %d price is %f",ID,age,price);
        
        
    }
    return 0;
}


//
//  Dog.h
//  basic1.1
//
//  Created by lyricdon on 15/4/24.
//  Copyright (c) 2015年 lyricdon. All rights reserved.
//

#ifndef basic1_1_Dog_h
#define basic1_1_Dog_h

@interface Dog:NSObject{
    @protected
    int ID;
    @public
    int age;
    @private
    float price;
}


//凡是以initxxxx开头的都是构造函数
-(id)init;
//函数名为init  不带参数
-(id)initWithID:(int)newID;
//带一个int参数
-(id)initWithID:(int)newID andAge:(int)newAge;
-(id)initWithID:(int)newID andAge:(int)newAge andPrice:(float)newPrice;

-(void)setID:(int)newID;
-(int)getID;
//set/get ID

-(void)setAge:(int)newAge;
-(int)getAge;

-(void)setPrice:(float)newPrice;
-(float)getPrice;

-(void)setID:(int)newID andAge:(int)newAge;
-(void)setID:(int)newID andAge:(int)newAge andPrice:(float)newPrice;
//set id age price



@end

#endif



//
//  Dog.m
//  basic1.1
//
//  Created by lyricdon on 15/4/24.
//  Copyright (c) 2015年 lyricdon. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Dog.h"

@implementation Dog

-(id)init
{
    return [self initWithID:1];
//    self=[super init];
//    //self表示父类
//    //self表示对象自己
//    if(self){
//        ID=1;
//        age=2;
//        price=60.0f;
//    }
//    return self;
}
-(id) initWithID:(int)newID
{
    return [self initWithID:newID andAge:2];
//    self=[super init];
//    if(self){
//        ID=newID;
//        age=2;
//        price=60.0f;
//    }
//    return self;
}

-(id)initWithID:(int)newID andAge:(int)newAge
{
    return [self initWithID:newID andAge:newAge andPrice:10.6f];
//    self=[super init];
//    if(self){
//        ID=newID;
//        age=newAge;
//        price=60.0f;
//    }
//    return self;
}

-(id)initWithID:(int)newID andAge:(int)newAge andPrice:(float)newPrice{
   
    self=[super init];
    if(self){
        ID=newID;
        age=newAge;
        price=newPrice;
    }
    return self;
}


-(void)setID:(int)newID
{
    ID=newID;
}
-(int)getID
{
    return ID;
}

-(void)setAge:(int)newAge
{
    age=newAge;
}

-(int)getAge
{
    return age;
}


-(void)setPrice:(float)newPrice
{
    price=newPrice;
}
-(float)getPrice
{
    return price;
}


-(void)setID:(int)newID andAge:(int)newAge
{
  
    ID=newID;
    age=newAge;
}
-(void)setID:(int)newID andAge:(int)newAge andPrice:(float)newPrice
{
    ID=newID;
    age=newAge;
    price=newPrice;
}






@end


作者: lyricdon    时间: 2015-4-24 14:16
提示的是  break point 1.1
里面内容是:
dog1        Dog *        0x100300580        0x0000000100300580
argv        const char **        0x7fff5fbff848        0x00007fff5fbff848
argc        int        1        1




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2