tailieunhanh - Programming in Objective-C 2.0 edition phần 7

trong chương trình là một con trỏ là c, mà là thu được bằng cách áp dụng các nhà điều hành địa chỉ c. biến (Lưu ý rằng khởi tạo này sẽ đã tạo ra một lỗi biên dịch đã c được xác định sau khi tuyên bố này bởi vì một biến luôn luôn phải được khai báo trước khi giá trị của nó có thể được tham chiếu trong một biểu thức.) | Array Objects 345 lower-level array constructs provided by the language might be more efficient in terms of both memory usage and execution speed. Refer to the section titled Arrays in Chapter 13 for more information. Making an Address Book Let s take a look at an example that starts to combine a lot of what you ve learned to this point by creating an address address book will contain address cards. For the sake of simplicity your address cards will contain only a person s name and email address. Extend this concept to other information such as address and phone number is straightforward but we leave that as an exercise for you at the end of this chapter. Creating an Address Card We start by defining a new class called ll want the capability to create a new address card set its name and email fields retrieve those fields and print the card. In a graphics environment you could use some nice routines such as those provided by the Application Kit framework to draw your card onscreen. But here you stick to a simple Console interface to display your address cards. Program shows the interface file for your new AddressCard re not going to synthesize the accessor methods yet writing them yourself offers valuable lessons. Program Interface File import Foundation import Foundation @interface AddressCard NSObject . NSString name NSString email - void setName NSString theName - void setEmail NSString theEmail - NSString name - NSString email - void print @end 2 Mac OS X provides an entire Address Book framework which offers extremely powerful capabilities for working with address books. 346 Chapter 15 Numbers Strings and Collections This is straightforward as is the implementation file in Program . Program Implementation File import implementation AddressCard - void setName NSString theName . name NSString alloc initWithString theName - void setEmail NSString

TỪ KHÓA LIÊN QUAN