当前位置:网站首页>Objective C attribute keyword
Objective C attribute keyword
2022-07-04 03:34:00 【Zyryck】
Two ways to access and assign member variables :
One .get set The way
@interface Person : NSObject{
// Member variables
NSString* _name;
}
-(void)setName:(NSString*)name;
-(NSString*)name;
@end#import <Foundation/Foundation.h>
#import "Person.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Person* p1 = [Person new];
[p1 name];
[p1 setName:@"dancer"];
}
return 0;
}
Two . Attribute mode
[email protected](strong, nonatomic)
@interface Person : NSObject{
// Member variables
NSString* _name;
}
// attribute
@property(strong, nonatomic)NSString* name;
@end#import <Foundation/Foundation.h>
#import "Person.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Person* p1 = [Person new];
p1.name = @"dancer";
NSString* name = p1.name;
NSLog(@"name = %@",name);
}
return 0;
}
2. Statement property Statement synthesize
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface Person : NSObject{
NSInteger _age;
}
// attribute
@property(assign, nonatomic)NSInteger age;
@end
NS_ASSUME_NONNULL_END
#import "Person.h"
@implementation Person
@synthesize age;
@end3. Omit attribute method of member variable
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface Person : NSObject{
NSInteger _age;
}
// attribute
@property(strong, nonatomic)NSString* name;
@property(assign, nonatomic)NSInteger age;
// No corresponding member variable can automatically generate a private member variable _ Property name
@property(assign, nonatomic)NSInteger weight;
@end
NS_ASSUME_NONNULL_ENDUse synthesize Modify the name of the automatically generated member variable
#import "Person.h"
@implementation Person
@synthesize age;
// Use synthesize Modify the name of the automatically generated member variable
@synthesize weight = _myWeight;
@end
边栏推荐
- [PaddleSeg 源码阅读] PaddleSeg计算Dice
- Don't disagree, this is the most powerful "language" of the Internet
- [PaddleSeg 源码阅读] PaddleSeg 自定义数据类
- Which product is better for 2022 annual gold insurance?
- [Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
- POSTECH | option compatible reward reverse reinforcement learning
- Add token validation in swagger
- Unity knapsack system (code to center and exchange items)
- warning: LF will be replaced by CRLF in XXXXXX
- Unity controls the selection of the previous and next characters
猜你喜欢

Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex

PID of sunflower classic

Li Chuang EDA learning notes 13: electrical network for drawing schematic diagram

logistic regression

National standard gb28181 protocol platform easygbs fails to start after replacing MySQL database. How to deal with it?

渗透实战-guest账户-mimikatz-向日葵-sql提权-离线解密
![[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love](/img/ab/066923f1aa1e8dd8dcc572cb60a25d.jpg)
[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love

2022-07-03:数组里有0和1,一定要翻转一个区间,翻转:0变1,1变0。 请问翻转后可以使得1的个数最多是多少? 来自小红书。3.13笔试。

Fudan released its first review paper on the construction and application of multimodal knowledge atlas, comprehensively describing the existing mmkg technology system and progress

There is no need to authorize the automatic dream weaving collection plug-in for dream weaving collection
随机推荐
投资深度思考
2022 registration examination for safety production management personnel of fireworks and firecracker production units and examination skills for safety production management personnel of fireworks an
Want to do something in production? Then try these redis commands
System integration meets the three business needs of enterprises
Recent learning fragmentation (14)
Nbear introduction and use diagram
In my spare time, I like to write some technical blogs and read some useless books. If you want to read more of my original articles, you can follow my personal wechat official account up technology c
1day vulnerability pushback skills practice (3)
Is online futures account opening safe and reliable? Which domestic futures company is better?
Consul of distributed service registration discovery and unified configuration management
查詢效率提昇10倍!3種優化方案,幫你解决MySQL深分頁問題
Hospital network planning and design document based on GLBP protocol + application form + task statement + opening report + interim examination + literature review + PPT + weekly progress + network to
What kind of experience is it when the Institute earns 20000 yuan a month!
The first spring of the new year | a full set of property management application templates are presented, and Bi construction is "out of the box"
(column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)
POSTECH | option compatible reward reverse reinforcement learning
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
数据库SQL语句汇总,持续更新......
Leecode 122. Zuijia timing of buying and selling stocks ②
Unity writes a character controller. The mouse controls the screen to shake and the mouse controls the shooting