objective-c之struct

//
//  main.m
//  struct
//
//  Created by wu jianhua on 16-8-3.
//  Copyright (c) 2016年 wujianhua. All rights reserved.
//

#import <Foundation/Foundation.h>

struct Books
{
    NSString *title;
    NSString *author;
    NSString *subject;
    int   book_id;
};

@interface SampleClass : NSObject

- (void) printBook:(struct Books) book;

- (void) printBook2:(struct Books*)book;

@end

@implementation SampleClass


- (void)printBook:(struct Books)book
{
    NSLog(@"Book title : %@", book.title);
    NSLog(@"Book author : %@", book.author);
    NSLog(@"Book subject : %@ ", book.subject);
    NSLog(@"Book book_id : %d ", book.book_id);
                          
}

- (void)printBook2:(struct Books *)book
{
    NSLog(@"Book title : %@", book->title);
    NSLog(@"Book author : %@", book->author);
    NSLog(@"Book subject : %@ ", book->subject);
    NSLog(@"Book book_id : %d", book->book_id);
    
}

@end

void test001()
{
    struct Books Book1;        /* Declare Book1 of type Book */
    struct Books Book2;        /* Declare Book2 of type Book */
    
    /* book 1 specification */
    Book1.title = @"Objective-C Programming";
    Book1.author = @"Nuha Ali";
    Book1.subject = @"Objective-C Programming Tutorial";
    Book1.book_id = 6495407;
    
    /* book 2 specification */
    Book2.title = @"Telecom Billing";
    Book2.author = @"Zara Ali";
    Book2.subject = @"Telecom Billing Tutorial";
    Book2.book_id = 6495700;
    
    /* print Book1 info */
    NSLog(@"Book 1 title : %@", Book1.title);
    NSLog(@"Book 1 author : %@", Book1.author);
    NSLog(@"Book 1 subject : %@", Book1.subject);
    NSLog(@"Book 1 book_id : %d", Book1.book_id);
    
    
    /* print Book2 info */
    NSLog(@"Book 2 title : %@", Book2.title);
    NSLog(@"Book 2 author : %@", Book2.author);
    NSLog(@"Book 2 subject : %@ ", Book2.subject);
    NSLog(@"Book 2 book_id : %d ", Book2.book_id);
    
}
void test002()
{
    
    struct Books Book1;        /* Declare Book1 of type Book */
    struct Books Book2;        /* Declare Book2 of type Book */
    
    /* book 1 specification */
    Book1.title = @"Objective-C Programming";
    Book1.author = @"Nuha Ali";
    Book1.subject = @"Objective-C Programming Tutorial";
    Book1.book_id = 6495407;
    
    /* book 2 specification */
    Book2.title = @"Telecom Billing";
    Book2.author = @"Zara Ali";
    Book2.subject = @"Telecom Billing Tutorial";
    Book2.book_id = 6495700;
    
    SampleClass *sc=[[SampleClass alloc] init];
    
    [sc printBook:Book1];
    
    [sc printBook:Book2];
    
}
void test003()
{
    struct Books Book1;        /* Declare Book1 of type Book */
    struct Books Book2;        /* Declare Book2 of type Book */
    
    /* book 1 specification */
    Book1.title = @"fuck Objective-C Programming";
    Book1.author = @"Nuha Ali";
    Book1.subject = @"Objective-C Programming Tutorial";
    Book1.book_id = 6495407;
    
    /* book 2 specification */
    Book2.title = @"Telecom Billing";
    Book2.author = @"Zara Ali";
    Book2.subject = @"Telecom Billing Tutorial";
    Book2.book_id = 6495702;
    
    SampleClass *sc=[[SampleClass alloc] init];
    
    [sc printBook2:&Book1];
    [sc printBook2:&Book2];
    
}
int main(int argc, const char * argv[])
{

    test001();
    test002();
    test003();
    
    
    return 0;
};



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值