objective-c之struct

来源:互联网 发布:培罗成西服淘宝店 编辑:程序博客网 时间:2024/06/05 17:18
////  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);    }@endvoid 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