欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

IOS开发 property synthesize用法 CocoaObjective-C 

程序员文章站 2022-06-09 18:30:55
...
在JAVA中有对象有get set方法。在oc中是 property synthesize属性

用法:

Person.h:
#import <Foundation/Foundation.h>

@interface Person : NSObject
{
    int myNumber;
    int age;
    NSString *name;
}
@property(nonatomic) int myNumber;

-(void) printInfo;

@end


Person.m

#import "Person.h"

@implementation Person
@synthesize myNumber;

-(void)printInfo{
    NSLog(@"Person number is:%d",myNumber);
}

@end


main.m


#import <Foundation/Foundation.h>
#import "Person.h"
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        NSLog(@"Hello, World!");
        
        Person *person =[[Person alloc] init];
        [person setMyNumber:100];
        NSLog(@"Person number:%d",[person myNumber]);
    
        

    }
    return 0;
}


[img][/img]
  • IOS开发 property synthesize用法 
            
    
    
        CocoaObjective-C 
  • 大小: 12.3 KB
  • IOS开发 property synthesize用法 
            
    
    
        CocoaObjective-C 
  • 大小: 169.3 KB
相关标签: Cocoa Objective-C