gpt4 book ai didi

ios - 基本的 iOS 代码行解释

转载 作者:可可西里 更新时间:2023-11-01 05:56:43 25 4
gpt4 key购买 nike

tutorial我正在研究定义了以下方法。

- (void)addBirdSightingWithSighting:(BirdSighting *)sighting {
[self.masterBirdSightingList addObject:sighting];
}

教程描述如下:

This method creates and initializes a new BirdSighting object by sending to the initWithName:location:date: method the name and location the user entered, along with today’s date. Then, the method adds the new BirdSighting object to the array.

在我的数据模型 BirdSighting 类中有一个 initWithName:location:date: 方法。上面的方法被添加到数据 Controller ,它只是将 BirdSighting 对象添加到 masterBirdSightingList 可变数组。

我不明白的是教程说 BirdSighting 对象被发送到 initWithName:location:date: 方法,而我没有看到这个?

  • 这是因为 (BirdSighting *) 方法参数中的 * 吗?我知道 * 是一个指向对象的指针,但它是否创建了一个新对象并调用了它的默认 init 方法?仅仅因为我将 initWithName:location:date 添加到 BirdSighting 类,它是否自动成为我的默认 init 方法?

最佳答案

那里没有魔法。你是对的。该行代码不会创建或初始化 BirdSighting 对象。

添加:

您可能比许多人更早发现 Apple 代码和文档都不是完美的。有时他们甚至有严重的问题。当您遇到不协调时,最好相信您的直觉并进行一些您自己的测试。

关于ios - 基本的 iOS 代码行解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13849183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com