通訊錄是乙個字典,key為a-z,對應的value為陣列,陣列裡存的是相應的資訊,人的資訊也寫成了字典.僅供參考,可以實現要求功能
主函式內容:
nsmutabledictionary*addressbook = [[nsmutabledictionaryalloc] init];
person*k = [personpersonwithname:
@"k"
***:@"男
"number:
@"123456678"
address:
@"藍鷗"];
person*l = [personpersonwithname:
@"l"
***:@"女
"number:
@"123321332"
address:
@"藍鷗"];
person*y = [personpersonwithname:
@"y"
***:@"女
"number:
@"1231231231"
address:
@"藍鷗"];
addressbook *book = [[addressbook
alloc]initwithbook:addressbook];
[book addperson:y];
[book addperson:l];
[book addperson:k];
//[book showallpersonname]; 顯示所有人
//[book showgroup:@"w"]; 顯示w組
//[book findperson:@"123321332"]; 按**找人
//[book showfemale]; 輸出所有女性
//[book removegroup:@"w"]; 刪除組
//[book removepeople:@"k"]; 按名字刪除
person類 .h檔案
#import
@inte***ce person : nsobject
@property(nonatomic, retain)
nsstring
*name;
@property(nonatomic, retain)
nsstring
****;
@property(nonatomic, retain)
nsstring
*number;
@property(nonatomic, retain)
nsstring
*address;
@property(nonatomic, retain)
nsmutabledictionary
*people;
- (id)initwithname:(nsstring *)name ***:(nsstring *)*** number:(nsstring *)number address:(nsstring *)address;
+ (id)personwithname:(nsstring *)name ***:(nsstring *)*** number:(nsstring *)number address:(nsstring *)address;
@end
.m檔案
#import "person.h"
@implementationperson
- (id)initwithname:(nsstring *)name ***:(nsstring *)*** number:(nsstring *)number address:(nsstring *)address
returnself; }
+ (id)personwithname:(nsstring *)name ***:(nsstring *)*** number:(nsstring *)number address:(nsstring *)address
@end
addressbook類.h
#import
@class
person;
@inte***ce addressbook : nsobject
@property(nonatomic, retain)
nsmutabledictionary
*book;
- (id)initwithbook:(nsmutabledictionary *)book;
- (void)addperson:(person *)person;
- (void)showgroup:(nsstring *)group;
- (void)findperson:(nsstring *)number;
- (void)showfemale;
- (void)removepeople:(nsstring *)name;
- (void)removegroup:(nsstring *)group;
- (void)showallpersonname;
@end
.m檔案
#import "addressbook.h"
#import "person.h"
@implementationaddressbook
- (id)initwithbook:(nsmutabledictionary *)book
}returnself; }
- (void)addperson:(person *)person}}
- (void)showgroup:(nsstring *)group}}
}}- (void)findperson:(nsstring *)number}}
}}}- (void)showfemale}}
}}}- (void)removepeople:(nsstring *)name}}
}}- (void)removegroup:(nsstring *)group}}
}- (void)showallpersonname}}
}@end
OC簡易通訊錄
addressbook.m implementation addressbook 重寫初始化方法 instancetype init return self instancetype init return self 新增新聯絡人 void addcontact contact contact el...
實現中等通訊錄 OC
實現中等難度通訊錄。需求 1 定義聯絡 類contact。例項變數 姓名 拼 音,首字母 大寫 性別 號碼 住址 分組名稱 年齡。方法 定義初始化方法 姓名 號碼 顯示聯絡人資訊 2 在main.m中定義字典,分組管理所有聯絡人。分組名為26個大寫的英文本母。3 可以新增聯絡 物件,如果姓名或 號碼...
OC中簡易通訊錄框架
contact.h import inte ce contact nsobject void setname nsstring name nsstring name void setgender nsstring gender nsstring gender void setphonenumber ...