Reputation: 1155
This code works in Playground, but I get a compile error when I define this in my project in Xcode 7.2
Here is my Playground screenshot https://goo.gl/yJ4Q75
Error is: method does not override any method in the super class
public class A {
private func myUnavailableMethod() {
print("A. private func myUnavailableMethod()")
}
}
public class B : A {
override func myUnavailableMethod() {
print("B. func myUnavailableMethod()")
}
}
Motivation to this Playground was an error when trying to override a method, compiler was complaining as "Not available"
class MySFSafariViewController: SFSafariViewController {
override init() {
}
}
---- FOUND HOW THEY MARKED a method as unavailable.
When jumping to the Objective C declaration.
@interface SFSafariViewController : UIViewController
/*! @abstract The view controller's delegate */
@property (nonatomic, weak, nullable) id<SFSafariViewControllerDelegate> delegate;
****- (instancetype)init NS_UNAVAILABLE;****
Upvotes: 0
Views: 78
Reputation: 7466
The meaning of private/internal/public is different in Swift compared to some other languages.
IF and it is an IF you have your classes as two separate files in the project, then it's pretty clear.
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
In Xcode Playground their are both in one file so the method is visible to class B.
Upvotes: 1
Reputation: 40030
The myUnavailableMethod
of class A is private, therefore it can't be overridden. Change the method declaration to be internal
by removing the private
keyword.
Upvotes: 0