Objective C 2.0 ¼òÃ÷½Ì³Ì (5) ÊôÐÔ(Property)
Objective C 2.0 ¼òÃ÷½Ì³Ì (5) ÊôÐÔ(Property)
×÷ÕߣºAdministrator
ÖÜÁù, 2009Äê 03ÔÂ 28ÈÕ 07:47
Objective C 2.0 ΪÎÒÃÇÌṩÁËproperty¡£Ëü´ó´ó¼ò»¯ÁËÎÒÃÇ´´½¨Êý¾Ý³ÉÔ±¶Áдº¯ÊýµÄ¹ý³Ì£¬¸üΪ¹Ø¼üµÄÊÇËüÌṩÁËÒ»ÖÖ¸üΪ¼ò½à£¬Ò×ÓÚÀí½âµÄ·½Ê½À´·ÃÎÊÊý¾Ý³ÉÔ±¡£
ÎÒÃÇÏÈÀ´¿´Ò»ÏÂÔÚObjective C 1.xÏÂÎÒÃÇÉùÃ÷BookÀàµÄÍ·Îļþ£º
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//
// Book.h
#import <Cocoa/Cocoa.h>
@interface Book : NSObject {
NSString *title;
NSNumber* numofpages;
}
- (id)initWithTitle:(NSString*) booktitle andNumofpages:(NSNumber*) num;
- (NSString*) title;
- (void) setTitle:(NSString*)newtitle;
- (NSNumber*) numofpages;
- (void) setNumofpages:(NSNumber*)newnumofpages;
- (NSString*) summary;
@end
ÔÚObjective C 2.0Ï£¬ÎÒÃÇ¿ÉÒÔͨ¹ýÉùÃ÷ÓëÊý¾Ý³ÉԱͬÃûµÄpropertyÀ´Ê¡È¥¶Áдº¯ÊýµÄÉùÃ÷¡£´úÂëÈçÏÂËùʾ£º
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//
// Book.h
#import <Cocoa/Cocoa.h>
@interface Book : NSObject {
NSString *title;
NSNumber* numofpages;
}
- (id)initWithTitle:(NSString*) booktitle andNumofpages:(NSNumber*) num;
@property (retain) NSString* title;
@property (retain) NSNumber* numofpages;
@property (readonly) NSString* summary;
@end
ÎÒÃÇΪÿһ¸öÊý¾Ý³ÉÔ±ÉùÃ÷ÁËÒ»¸öproperty¡£¼´Ê¹BookÀàÖÐûÓÐsummaryÕâ¸öÊý¾Ý³ÉÔ±£¬ÎÒÃÇͬÑù¿ÉÒÔÉùÃ÷Ò»¸öÃûΪsummaryµÄproperty¡£ÉùÃ÷propertyµÄÓ﷨Ϊ£º
@property (²ÎÊý) ÀàÐÍ Ãû×Ö;
ÕâÀïµÄ²ÎÊýÖ÷Òª·ÖΪÈýÀࣺ¶ÁдÊôÐÔ£¨readwrite/readonly£©£¬setterÓïÒ⣨assign/retain/copy£©ÒÔ¼°atomicity£¨nonatomic£©¡£
assign/retain/copy¾ö¶¨ÁËÒÔºÎÖÖ·½Ê½¶ÔÊý¾Ý³ÉÔ±¸³ÓèÐÂÖµ¡£ÎÒÃÇÔÚÉùÃ÷summary properyʱʹÓÃÁËreadonly£¬ËµÃ÷¿Í»§¶ËÖ»ÄܶԸÃproperty½øÐжÁÈ¡¡£atomicityµÄĬÈÏÖµÊÇatomic£¬¶ÁÈ¡º¯ÊýΪÔ×Ó²Ù×÷¡£
ÏÂÃæÎÒÃÇÀ´¿´Ò»ÏÂÔÚObjective C 1.x ÏÂimplementationÎļþ£º
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Ïà¹ØÎĵµ£º
ÁËCÈ»ºóC++£¬È»ºóMFC/Windows,È»ºóÊÇC#,ÆäÖÐÊý¾ÝÀàÐͺܶ࣬ÓÉ»ù±¾ÀàÐÍÑÜÉúµÄtypedefÀàÐÍÒ²N¶à¡£ÊìÖª»ù±¾Êý¾ÝÀàÐÍÊÇÎÒÃÇÕýÈ·±í´ïʵ¼ÊÎÊÌâÖи÷ÖÖÊý¾ÝµÄÇ°ÌᣬÒò´ËÎÒ·ÖÀà×ܽáÁËÒ»ÏÂC/C++/Windows /C#»ù±¾Êý¾ÝÀàÐÍ£¬ÒÔ±ãÈÕºó²éÔÄ¡£
ANSI C/C++»ù±¾Êý¾ÝÀàÐÍ£º
Type
Size
Ê ......
ʱ³£ÔÚcppµÄ´úÂëÖ®Öп´µ½ÕâÑùµÄ´úÂë:
#ifdef __cplusplus
extern "C" {
#endif
//Ò»¶Î´úÂë
#ifdef __cplusplus
}
#endif
ÕâÑùµÄ´úÂëµ½µ×ÊÇʲôÒâ˼ÄØ£¿Ê×ÏÈ£¬__cplusplusÊÇcppÖеÄ×Ô¶¨Òåºê£¬ÄÇô¶¨ÒåÁËÕâ¸öºêµÄ»°±íʾÕâÊÇÒ»¶ÎcppµÄ´úÂ룬Ҳ¾ÍÊÇ˵£¬ÉÏÃæµÄ´úÂëµÄº ......
http://man.lupaworld.com/content/develop/c&c++/c/c.htm
1. Èç¹û²ÎÊýÊÇÖ¸Õ룬ÇÒ½ö×÷ÊäÈëÓã¬ÔòÓ¦ÔÚÀàÐÍÇ°¼Óconst£¬ÒÔ·ÀÖ¹¸ÃÖ¸ÕëÔÚº¯ÊýÌåÄÚ±»ÒâÍâÐÞ¸Ä
2. ÔÚº¯ÊýÌåµÄ“Èë¿Ú´¦”£¬¶Ô²ÎÊýµÄÓÐЧÐÔ½øÐмì²é
ÔÚº¯ÊýÌåµÄ“³ö¿Ú´¦”£¬¶ÔreturnÓï¾äµÄÕýÈ·ÐÔºÍЧÂʽøÐмì ......
×÷ÕߣºKevin Lynx¡¡À´Ô´£ºC++²©¿Í
ת×Ô:http://www.kuqin.com/language/20080319/4797.html
ÖÚ¶àC++Êé¼®¶¼ÖÒ¸æÎÒÃÇCÓïÑÔºêÊÇÍò¶ñÖ®Ê×£¬µ«ÊÂÇé×ܲ»ÈçÎÒÃÇÏëÏóµÄÄÇô»µ£¬¾ÍÈçͬgotoÒ»Ñù¡£ºêÓÐ
Ò»¸öºÜ´óµÄ×÷Ó㬾ÍÊÇ×Ô¶¯ÎªÎÒÃDzúÉú´úÂë¡£Èç¹û˵ģ°å¿ÉÒÔΪÎÒÃDzúÉú¸÷ÖÖÐͱðµÄ´úÂë(ÐͱðÌæ»»)£¬
ÄÇôºêÆäʵ¿ÉÒÔΪÎÒÃÇÔÚ·ûºÅÉÏ ......
Windows C ³ÌÐòÉè¼ÆÈëÃÅÓëÌá¸ß
http://download.chinaitlab.com/program/files/13246.html
µ¥Æ¬»úCÓïÑÔÈëÃÅ
http://download.chinaitlab.com/program/files/12907.html
C++ ÈëÃÅ»ù´¡½Ì³Ì
http://download.chinaitlab.com/program/files/7617.html
CÓïÑÔ³£ÓÃËã·¨Ô´´úÂë
http://download.chinaitlab.com/program/files ......