• error: synthesized property 'name' must either be named the same as a compatible instance variable or must explicitly name an instance variable问题解决


    #import <Foundation/Foundation.h>
    
    @interface Person : NSObject{
        NSString * _name;
        NSUInteger _age;
    }
    
    @property (nonatomic, copy) NSString* name;
    @property (nonatomic, assign) NSUInteger age;
    
    @end
    @implementation Person
    
    @synthesize name = _name;
    @synthesize age = _age;
    
    @end

    正确实现如上述代码,之前参照Object-C程序设计 (第4版)写的实例,就是报:

    error: synthesized property 'name' must either be named the same as a compatible instance variable or must explicitly name an  instance variable错误。

    参考书中改代码如下:

    #import <Foundation/Foundation.h>
    
    @interface Person : NSObject
    
    @property (nonatomic, copy) NSString* name;
    @property (nonatomic, assign) NSUInteger age;
    
    @end
  • 相关阅读:
    【Cocos2d js系列】创建一个弹出框
    Java内存模型
    linux系统-CPU上下文切换
    网络编程-套接字(socket)
    Java虚拟机组成及原理
    swarm
    docker-machine
    存储卷类型
    NOSQL数据库使用存储卷
    建立持久化的容器
  • 原文地址:https://www.cnblogs.com/yanwei-wang/p/8676100.html
Copyright © 2020-2023  润新知