Tôi đào sâu hơn một chút trong các khung công tác iOS và tôi đã quan sát thấy hành vi mặc định của mô tả sdk iOS không phải là để đặt "\ n" nhưng ";".
Ví dụ:
UIFont *font = [UIFont systemFontOfSize:18];
NSLog(@"FontDescription:%@",[font description]);
NSMutableArray *fontsArray = [NSMutableArray arrayWithCapacity:0];
for(int index = 0; index < 10; index++) {
[fontsArray addObject:font];
}
NSLog(@"FontsArrayDescription:%@",[fontsArray description]);
thỏa ra là:
FontDescription: font-family: "Helvetica"; font-weight: bình thường; font-style: bình thường; font-size: 18px
FontsArrayDescription :(
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px"
)
Vì vậy, tôi đã quyết định sử dụng phương pháp tương tự với lớp học của tôi.
- (NSString *)description {
NSString *descriptionString = [NSString stringWithFormat:@"Name: %@; Address: %@;", self.name, self.address];
return descriptionString;
}
Và đặt ra sẽ là:
"Name: Alex; Địa chỉ: số địa chỉ;"
Đối với đối tượng, bản thân nó.
objecsArrayDescription :(
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;"
)
Đối với một mảng của các đối tượng.
bạn sẽ phải lặp trên các yếu tố và gọi 'description' trên mỗi. Mô tả mảng được định dạng đầu ra, có thể ngắn mạch một số thứ như "\ n", để giữ định dạng phù hợp –
xem [http://stackoverflow.com/a/1828689/971401](http://stackoverflow.com/a/1828689/971401). Câu trả lời có thể có thể giúp bạn. –