gpt4 book ai didi

ios - swift 2.1,Xcode 7.2。简单的新手关于为什么它在 Playground 中有效但在应用程序中不起作用

转载 作者:行者123 更新时间:2023-11-29 01:11:36 25 4
gpt4 key购买 nike

此代码在 Playground 中有效,但当我在 Xcode 7.2 的项目中定义此代码时出现编译错误

这是我的 Playground 截图 https://goo.gl/yJ4Q75

错误是:方法没有覆盖父类(super class)中的任何方法

public class A {
private func myUnavailableMethod() {
print("A. private func myUnavailableMethod()")
}
}

public class B : A {
override func myUnavailableMethod() {
print("B. func myUnavailableMethod()")
}
}

尝试重写方法时,这个 Playground 的动机是错误的,编译器提示“不可用”

class MySFSafariViewController: SFSafariViewController {
override init() {

}
}

---- 了解他们如何将方法标记为不可用。

跳转到 Objective C 声明时。

@interface SFSafariViewController : UIViewController

/*! @abstract The view controller's delegate */
@property (nonatomic, weak, nullable) id<SFSafariViewControllerDelegate> delegate;

****- (instancetype)init NS_UNAVAILABLE;****

最佳答案

private/internal/public 在 Swift 中的含义与其他一些语言不同。

如果是,如果您将类作为项目中的两个单独文件,那么就很清楚了。

private - scope is visibility is the file that holds the code
internal - scope of visibility is the namespace
public - scope of visibility is full access from anywhere

在 Xcode Playground 中,它们都在一个文件中,因此该方法对类 B 可见。

关于ios - swift 2.1,Xcode 7.2。简单的新手关于为什么它在 Playground 中有效但在应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35689477/

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