Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 453 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
453
Dung lượng
4,54 MB
Nội dung
[...]... Specifies the category for your app in the App Store 31 32 CHAPTER 1: Application Development Option Description Create DocumentBased Application Include the setup that you need to work with an NSDocumentbased application Document Extension Document extension associated with this app (for document-based apps) Use Core Data Automatically includes the Core Data Stack to be used for data persistence Use Automatic... NSLog(@"car is %@", car.name); Or you can use properties with standard Objective-C messaging: [car setName:@"New Car Name"]; NSLog(@"car.name is %@", [car name]); You will see both examples of accessing properties as you look at more Objective-C code Dot notation (the first example) is a relatively new Objective-C feature that was added with Objective-C 2.0 Note that dot notation has the advantage of being... Figure 1-3 CHAPTER 1: Application Development Figure 1-3 Window after action method executed 1.11 Creating a Mac Window-Based Application From Xcode Problem The recipes so far have simply been using the compiler from the command line to create Objective-C programs However, if you want to develop a rich Mac application, you need to use Xcode to get it ready for the App Store NOTE: The Mac App Store is... course, Car doesn’t do much until you add your own custom properties and methods, which you’ll see in the upcoming recipes 1.4 Code Property Assessors Problem Custom classes need to represent the attributes of the entities they are modeling You need to know how to define and implement properties in Objective-C to do this Solution To implement properties for custom classes, you must declare properties in the... rather Reference Counting manage memory yourself Include Unit Test Automatically includes setup that you need for unit testing your app Include Spotlight Importer An option for document-based applications to allow the app’s document files to be referenced by Spotlight After you choose your initial settings, click Next to choose your project location Here you may choose to use the version control system... maccommandlineapp, you will see output that looks something like this: car.name is Sports Car car.name is New Car Name logout [Process completed] 1.6 Adding a Class Method to a Custom Class Problem In Objective-C, you can send messages to either classes or objects to get things done If you want your custom class to be able to respond to a message, you must first code a class method Solution To add a... see output that looks something like this: Today's date is 2011-12-19 14:23:11 +0000 and this class represents a car logout [Process completed] 1.7 Adding an Instance Method to a Custom Class Problem In Objective-C, you can send messages to either classes or objects to get things done If you want objects that have been instantiated from your custom class to be able to respond to a message, you must first... New Car logout [Process completed] 1.8 Extending a Class with a Category Problem You would like to add methods and behavior to a class, but you would rather not create an entire new subclass Solution In Objective-C, you can use categories to define and implement properties and methods that can later be attached to a class To do this, you need two files: a header file to list your interface and an implementation... Objective-C 2.0 Note that dot notation has the advantage of being more familiar to programmers who are used to other programming languages where dot notation is the standard practice The second example, regular Objective-C messaging, is still used often Choosing one method over another is mostly a matter of personal preference See Listings 1-4 through 1-6 for the code The Code Listing 1-4 Car.h #import ... Development 1.5 Code Property Assessors with @synthesize Problem Custom classes need to represent the attributes of the entities they are modeling You need to know how to define and implement properties in Objective-C to do this If you don’t want to code your own getter and setter methods, you can use the @synthesize as an alternative Solution To implement properties with @synthesize, you still need to declare .
compiles Objective-C programs. Here are some options that you may set when
using clang to compile your Objective-C programs:
-fobj means that Objective-C. as you look at more
Objective-C code. Dot notation (the first example) is a relatively new Objective-C
feature that was added with Objective-C 2.0. Note