Address Book Exercises

Source: Internet
Author: User

1 #import<Foundation/Foundation.h>2 //MVC Design Ideas3 //Model Data Models4 //View views5 //controller Controllers6 #import "ContactBook.h"7 intMainintargcConst Char*argv[]) {8 @autoreleasepool {9 [Contactbook test];Ten     } One     return 0; A}
main.m
1 #import<Foundation/Foundation.h>2 3 @interfaceContact:nsobject4@property NSString *name;5@property NSString *nickname;6@property NSString *gender;7@property NSString *phone;8@property NSString *Hometele;9@property NSString *Companytele;Ten@property NSString *Company ; One@property NSString *job; A@property NSString *Group; -@property NSString *companyaddress; -@property NSString *homeaddress; the@property NSString *birthday; -@property NSString *email; -@property NSString *Qqnumber; -@property NSString *Msnnumber; +@property NSString *remark; -  +  A  at  - @end
Contact.h
1 #import "Contact.h"2 3 @implementation Contact4 5-(NSString *) description{6     return[NSString stringWithFormat:@"name:%@, nickname:%@, gender:%@, phone:%@, hometele:%@, companytele:%@, company:%@, job:%@, group:%@, companyaddress:%@, homeaddress:%@, birthday:%@, email:%@, qqnumber:%@, msnnumber:%@, remark:%@", _name,_nickname,_gender,_phone,_hometele,_companytele,_company,_job,_group,_companyaddress,_homeaddress,_ Birthday,_email,_qqnumber,_msnnumber,_remark];7 }8 @end
CONTACT.M
1   #import  <foundation/foundation.h>2  3   @interface   Contactbook:nsobject {  4  nsmutablearray * _array;  5   6  + (void  ) test;  7 -(void   8 -(void   9   @end  
ContactBook.h
1 #import "ContactBook.h"2 #import "Contact.h"3 #definePATH @ "/users/wangqitai/desktop/archive/contacts.txt"4 #defineSHOW (a) NSLog (@ "%@", a);5 @implementationContactbook6- (ID) init {7     if(self =[Super Init]) {8_array =[[Nsmutablearray alloc] init];9 [self addcontacts];Ten     } One     returnSelf ; A } -  -- (void) addcontacts { the     //1 reading a string from a file -Nserror *A; -      -NSString * str = [NSString stringwithcontentsoffile:path encoding:nsutf8stringencoding error:&a]; + //NSLog (@ "%@", str); -Nsarray * contacts = [str componentsseparatedbystring:@"\ n"]; + //SHOW (contacts); A      for(inti =1; i<contacts.count; i++) { atNSString * Contactstr =Contacts[i]; -Nsarray * contact = [Contactstr componentsseparatedbystring:@","]; -Contact * Cont =[Contact alloc] init]; -Cont.name = contact[0]; -Cont.nickname = contact[1]; -Cont.gender = contact[2]; inCont.phone = contact[3]; -Cont.hometele = contact[4]; toCont.companytele = contact[5]; +Cont.company = contact[6]; -Cont.job = contact[7]; theCont.group = contact[8]; *Cont.companyaddress = contact[9]; $Cont.homeaddress = contact[Ten];Panax NotoginsengCont.birthday = contact[ One]; -Cont.email = contact[ A]; theCont.qqnumber = contact[ -]; +Cont.msnnumber = contact[ -]; ACont.remark = contact[ the]; the         //save each contact to an array + [_array Addobject:cont]; -     } $ } $  -- (void) Showinfo { -      for(Contact * Coninch_array) { theNSLog (@"%@", con); -     }Wuyi } the  -+ (void) Test { WuContactbook * Contactbook =[[Contactbook alloc] init]; - [Contactbook Showinfo]; About } $  - @end
CONTACTBOOK.M

The contact separates the properties of the contacts by wrapping them in a newline, separating

Address Book Exercises

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.