New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-1759] Subclassing UIColor leads to error : "Declarations from extensions cannot be overridden yet" #44368
Comments
Comment by Seyed Samad Gholamzadeh (JIRA) I have this problem too. |
Comment by swesthk (JIRA) Same problem here!!! |
Comment by Seyed Samad Gholamzadeh (JIRA) I think I found the cause of this problem. It seems since Xcode 8 apple don't allow to developers create subclass for UIColor. Subclassing Notes By the way I have written a small extension for UIColor that maybe solves your problem: |
Comment by Marc Knaup (JIRA) The subclassing notes for UIColor aren't new. Apple clearly allows subclassing. The Objective-C -> Swift import seems to have a bug which imports an extension initializer as extension UIColor {
@nonobjc required public convenience init(colorLiteralRed red: Float, green: Float, blue: Float, alpha: Float)
} The only workaround so far seems to be to add only convenience initializers in the subclass or to not add any initializers at all. That way the problematic initializer is inherited automatically. (Xcode 8.2) |
Comment by Martin Straub (JIRA) This is just annoying... Tried to get a nice solution using UIColor and Codable. But it's neither possible to add the Codable requirements in an extension, nor using subclasses because of this bug :-/ |
Comment by Sergey A. Novitsky (JIRA) I have observed the same for NSString (Xcode 9 and Swift 4). Xcode offers a fix for the missing required initializer of an extension:
But it obviously does not compile. |
Comment by Vitalii Budnik (JIRA) Xcode 10.2 (10E125) The problem is still here. The code below doesn't compile. import Foundation
#if os(iOS)
import UIKit
typealias NSColor = UIColor
#elseif os(macOS)
import AppKit
#endif
internal final class AnotherColorClass: NSColor {
internal init(param: Any) {}
@nonobjc required convenience init(
_colorLiteralRed red: Float,
green: Float,
blue: Float,
alpha: Float
)
{
fatalError("init(_colorLiteralRed:green:blue:alpha:) has not been implemented")
}
internal required init?(coder: NSCoder) {
fatalError("init?(coder:) has not been implemented")
}
#if os(macOS)
internal required init?(
pasteboardPropertyList propertyList: Any,
ofType type: NSPasteboard.PasteboardType
)
{
fatalError("init?(pasteboardPropertyList:ofType:) has not been implemented")
}
#endif
} |
Attachment: Download
Environment
macOS 10.11.5 (15F34)
Xcode 8.0 beta (8S128d)
Apple Swift version 3.0 (swiftlang-800.0.30 clang-800.0.24)
Additional Detail from JIRA
md5: 4a18f1c80354d3e40eb0894dc7e3be33
Issue Description:
When you subclassing UIColor, you need to add a @nonobjc required convenience public init(colorLiteralRed red: Float, green: Float, blue: Float, alpha: Float) method.
When adding it, the error "Declarations from extensions cannot be overridden yet" appears.
The text was updated successfully, but these errors were encountered: