当前位置:网站首页>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
边栏推荐
- Consul of distributed service registration discovery and unified configuration management
- [untitled]
- Leecode 122. Zuijia timing of buying and selling stocks ②
- WordPress collection WordPress hang up collection plug-in
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- Enhanced for loop
- Webhook triggers Jenkins for sonar detection
- [source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
- Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
- [PaddleSeg 源码阅读] PaddleSeg计算Dice
猜你喜欢

基于PHP的轻量企业销售管理系统

Webhook triggers Jenkins for sonar detection

Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami

Zhihu million hot discussion: why can we only rely on job hopping for salary increase? Bosses would rather hire outsiders with a high salary than get a raise?

Record a problem that soft deletion fails due to warehouse level error

Want to do something in production? Then try these redis commands

@Scheduled scheduled tasks

Have you entered the workplace since the first 00???

Explain AI accelerator in detail: why is this the golden age of AI accelerator?
![Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]](/img/ad/b675364fcaf5d874397fd0cbfec11b.jpg)
Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]
随机推荐
[UE4] parse JSON string
Aperçu du code source futur - série juc
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
[PaddleSeg 源码阅读] PaddleSeg计算Dice
Explain AI accelerator in detail: why is this the golden age of AI accelerator?
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"
2022-07-03:数组里有0和1,一定要翻转一个区间,翻转:0变1,1变0。 请问翻转后可以使得1的个数最多是多少? 来自小红书。3.13笔试。
CUDA basic knowledge
Future源碼一觀-JUC系列
Unity writes a character controller. The mouse controls the screen to shake and the mouse controls the shooting
MySQL data query optimization -- data structure of index
[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love
【.NET+MQTT】.NET6 環境下實現MQTT通信,以及服務端、客戶端的雙邊消息訂閱與發布的代碼演示
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
Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website
微信公众号网页授权
MySQL backup notes
Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]
Recursive structure
Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex