zoukankan      html  css  js  c++  java
  • synthesize 与dynamic的区别

    官方文档解释:
    @synthesize will generate getter and setter methods for your property. @dynamic just tells the compiler that the getter and setter methods are implemented not by the class itself but somewhere else (like the superclass)
     

    Uses for @dynamic are e.g. with subclasses of NSManagedObject (CoreData) or when you want to create an outlet for a property defined by a superclass that was not defined as an outlet:

    Super class:

    @property(nonatomic, retain)NSButton*someButton;

    ...

    @synthesize someButton;

    Subclass:

    @property(nonatomic, retain)IBOutletNSButton*someButton;
    ...
    @dynamic someButton;
     
    1:通过@synthesize 指令告诉编译器在编译期间产生getter/setter方法。
    2:通过@dynamic指令,自己实现方法。@dynamic 就是要告诉编译器,代码中用@dynamic修饰的属性,其getter和setter方法会在程序运行的时候或者用其他方式动态绑定,以便让编译器通过编译。其主要的作用就是用在NSManagerObject对象的属性声明上,由于此类对象的属性一般是从Core Data的属性中生成的,core data 框架会在程序运行的时候为此类属性生成getter和setter方法。
  • 相关阅读:
    JVM垃圾回收机制
    浅谈类的几个基础构造函数
    三次登陆用户名 和密码
    干迷宫
    记录人生中的第一个bug
    js三元运算符? :
    Linux云服务器 磁盘分区失败
    python基础中遇到的问题(TypeError: unhashable type: 'list')
    python亲密数设计
    源码编译安装Protobuf
  • 原文地址:https://www.cnblogs.com/lxd2502/p/5756601.html
Copyright © 2011-2022 走看看