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
Ïà¹ØÎĵµ£º
B/S½á¹¹£¨Browser/Server½á¹¹£©½á¹¹¼´ä¯ÀÀÆ÷ºÍ·þÎñÆ÷½á¹¹¡£
1.½ÚÔ¼³É±¾~~~~~
´ó´ó¼ò»¯Á˿ͻ§¶ËµçÄÔÔØºÉ£¬¼õÇáÁËϵͳά»¤ÓëÉý¼¶µÄ³É±¾ºÍ¹¤×÷Á¿£¬½µµÍÁËÓû§µÄ×ÜÌå³É±¾£¨TCO)!ËüÊÇÒ»´ÎÐÔµ½Î»µÄ¿ª·¢!
2.°²È«~~~
ËüÄÜÓÐЧµØ±£»¤Êý¾Ýƽ̨ºÍ¹ÜÀí·ÃÎÊȨÏÞ£¬·þÎñÆ÷Êý¾Ý¿âÒ²ºÜ°²È« ¡£ÔÚÍøÂç¸÷¹¤×÷վͨ¹ýWWWä¯ÀÀÆ÷¾ÍÄÜʵÏÖ¹¤×÷ҵΠ......
×î½üÔÚ×öÒ»¸öI2C¼üÅ̵ÄLinuxÇý¶¯£¬²Î¿¼ÁËÆäËûоƬµÄһЩ´úÂ룬ÆäÖÐÂ½Ðø·¢ÏÖÓÐЩÈÃÈËÃÔ»óµÄ¶«Î÷£¬°ÑÎÒµÄÃÔ»ó¼°Àí½âÔÚÕâÀï¼ÓÒԼǼ£º
1. i2c_driver½á¹¹ÌåµÄprobe³ÉÔ±µÄÔÐÍ£º
int (*probe)(struct i2c_client *, const struct i2c_device_id *);
¼´£ºprobeº¯Êý±»µ÷ÓÃʱ»á´ÓÉϱߴ«Á½¸ö¸ö²Î ......
Êý×鸳ֵÎÒ×ܽáһϰÉÒ²¾ÍÈýÖÖ£¬ÄÇcharµÄÀ´¾ÙÀý£º
¶¨ÒåµÄʱºòÖ±½Ó¸³Öµ.
1£ºchar a[20] = "Hello World!";
2: char a[20];
strcpy(a, "Hello World!");
3:char a[20] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
³£¼û´íÎó¸³Öµ·½Ê½:
1:char a[20];
a = "Hello World ......
×÷ÕߣºKevin Lynx¡¡À´Ô´£ºC++²©¿Í
ת×Ô:http://www.kuqin.com/language/20080319/4797.html
ÖÚ¶àC++Êé¼®¶¼ÖÒ¸æÎÒÃÇCÓïÑÔºêÊÇÍò¶ñÖ®Ê×£¬µ«ÊÂÇé×ܲ»ÈçÎÒÃÇÏëÏóµÄÄÇô»µ£¬¾ÍÈçͬgotoÒ»Ñù¡£ºêÓÐ
Ò»¸öºÜ´óµÄ×÷Ó㬾ÍÊÇ×Ô¶¯ÎªÎÒÃDzúÉú´úÂë¡£Èç¹û˵ģ°å¿ÉÒÔΪÎÒÃDzúÉú¸÷ÖÖÐͱðµÄ´úÂë(ÐͱðÌæ»»)£¬
ÄÇôºêÆäʵ¿ÉÒÔΪÎÒÃÇÔÚ·ûºÅÉÏ ......
Ò»¡¢c++ µ÷C:
/* cÓïÑÔÍ·Îļþ£ºcExample.h */
#ifndef C_EXAMPLE_H
#define C_EXAMPLE_H
#ifdef __cplusplus
extern "C"
{
#endif
int add(int x,int y);
#ifdef __cplusplus
}
#endif
#endif
/* cÓïÑÔʵÏÖÎļþ£ºcExample.c */
#include "cExample.h"
int add( int x, int y )
{
return ......