<<Effective OC>>读书笔记 --- 第六条 理解“属性”这一概念

OC代码

@interface Person : NSObject
@property(nonatomic)NSInteger age;
// @proerty(nonatimic) NSString name;
@end
@implementation Person
@end

使用property优势:

1、编译器自动合成 存取方法,
2、版本兼容,当OC对象新加入一个property,不用编译链接。
因为property早已经计算好偏移量,而直接使用变量则没有这样子的效果,需要重新编译链接才能计算出偏移量。

synthesize作用:目前XCODE7 都不会这么写

@property 声明一个setter getter 方法
@synthesize 实现setter getter 方法

那么我想只要一个getter 或者 setter方法怎么办呢?

使用@dynamic

@interface Person : NSObject{
    NSString* _name;
}

@property(nonatomic) NSInteger age;
@property(nonatomic) NSString name;
@end
@implementation Person
@dynamic name;

//- (void) setName:(NSString*) t
//{
//    _name = t;
//}

- (NSString*) name
{
    return _name;
}
// 省略一万行代码...
// 这里会报错,unrecognized selector sent to instance 0x7b870750'
// 找不到对应的SEL
self.name = @"顶顶顶顶顶"; 
@end

属性的内存管理语义

strong / weak
assign / copy

基于python实现的粒子群的VRP(车辆配送路径规划)问题建模求解+源码+项目文档+算法解析,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档 算法设计的关键在于如何向表现较好的个体学习,标准粒子群算法引入惯性因子w、自我认知因子c1、社会认知因子c2分别作为自身、当代最优解和历史最优解的权重,指导粒子速度和位置的更新,这在求解函数极值问题时比较容易实现,而在VRP问题上,速度位置的更新则难以直接采用加权的方式进行,一个常见的方法是采用基于遗传算法交叉算子的混合型粒子群算法进行求解,这里采用顺序交叉算子,对惯性因子w、自我认知因子c1、社会认知因子c2则以w/(w+c1+c2),c1/(w+c1+c2),c2/(w+c1+c2)的概率接受粒子本身、当前最优解、全局最优解交叉的父代之一(即按概率选择其中一个作为父代,不加权)。 算法设计的关键在于如何向表现较好的个体学习,标准粒子群算法引入惯性因子w、自我认知因子c1、社会认知因子c2分别作为自身、当代最优解和历史最优解的权重,指导粒子速度和位置的更新,这在求解函数极值问题时比较容易实现,而在VRP问题上,速度位置的更新则难以直接采用加权的方式进行,一个常见的方法是采用基于遗传算法交叉算子的混合型粒子群算法进行求解,这里采用顺序交叉算子,对惯性因子w、自我认知因子c1、社会认知因子c2则以w/(w+c1+c2),c1/(w+c1+c2),c2/(w+c1+c2)的概率接受粒子本身、当前最优解、全局最优解交叉的父代之一(即按概率选择其中一个作为父代,不加权)。
帮我检查一下为什么不能启动三层pom<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>demo</groupId> <!-- 子模块继承父项目 --> <parent> <groupId>com.aleks</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>demo</artifactId> <packaging>pom</packaging> <!-- 必须为 jar 或 war --> <dependencies> <!-- 继承父项目的依赖 --> <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.7.6</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency>--> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.7.6</version> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.7.6</version> </plugin> <plugin> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> </plugin> </plugins> </build> </project><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <parent> <artifactId>demo</artifactId> <groupId>com.aleks</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>deploy</artifactId> <packaging>pom</packaging> <modules> <module>main-deploy</module> </modules> <build> <plugins> <!-- 关键:Spring Boot 启动插件 --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.7.6</version> </plugin> </plugins> </build> </project> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <parent> <artifactId>deploy</artifactId> <groupId>com.aleks</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>main-deploy</artifactId> <packaging>jar</packaging> <build> <plugins> <!-- 关键:Spring Boot 启动插件 --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.7.6</version> </plugin> </plugins> </build> </project>
03-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值