Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITextField上的Swift扩展赢得';t在swift 1.2和xcode6.3上编译_Ios_Swift_Uitextfield_Xcode6.3 - Fatal编程技术网

Ios UITextField上的Swift扩展赢得';t在swift 1.2和xcode6.3上编译

Ios UITextField上的Swift扩展赢得';t在swift 1.2和xcode6.3上编译,ios,swift,uitextfield,xcode6.3,Ios,Swift,Uitextfield,Xcode6.3,在xCode更新6.3之后,我遇到了以下问题: “MyUItextViewExtension.swift:xx:xx:Method'editingRectForBounds'与Objective-C选择器'editingRectForBounds:'与具有相同Objective-C选择器的上一个声明冲突” 我的Swift代码是: extension UITextField{ func editingRectForBounds(bounds: CGRect) -> CG

在xCode更新6.3之后,我遇到了以下问题: “MyUItextViewExtension.swift:xx:xx:Method'editingRectForBounds'与Objective-C选择器'editingRectForBounds:'与具有相同Objective-C选择器的上一个声明冲突”

我的Swift代码是:

extension UITextField{      

    func editingRectForBounds(bounds: CGRect) -> CGRect{

        if self.leftView != nil {

            let textFieldPadding : CGFloat = 24.0
            return CGRectMake(bounds.origin.x + textFieldPadding, bounds.origin.y, bounds.size.width+textFieldPadding*2, bounds.size.height)
        } else {
            return textRectForBounds(bounds)
        }
    }

     func  textRectForBounds(bounds: CGRect) -> CGRect {

        if self.leftView != nil {

            let textFieldPadding : CGFloat = 24.0
            return CGRectMake(bounds.origin.x + textFieldPadding, bounds.origin.y, bounds.size.width+textFieldPadding*2, bounds.size.height)
        } else {
            let textFieldPadding : CGFloat = 8.0
            return CGRectMake(bounds.origin.x + textFieldPadding, bounds.origin.y, bounds.size.width+textFieldPadding*2, bounds.size.height)
        }
    }
}
我无法理解这个错误的原因。
在项目中,未定义UITextField上的另一类扩展…

editingRectForBounds
已存在于UITextField中,因此您可能应该覆盖它

从:

您不应该直接调用此方法。如果要为文本提供不同的编辑矩形,可以重写此方法并返回该矩形

编辑:

我之前不知道你想在扩展中使用这个。再说一次,如果我相信,如果我这次没有弄错你想要什么,那就有问题了:

不能使用扩展重写Objective-C类型上的现有方法或属性


editingRectForBounds
已存在于UITextField中,因此您可能应该
覆盖它

从:

您不应该直接调用此方法。如果要为文本提供不同的编辑矩形,可以重写此方法并返回该矩形

编辑:

我之前不知道你想在扩展中使用这个。再说一次,如果我相信,如果我这次没有弄错你想要什么,那就有问题了:

不能使用扩展重写Objective-C类型上的现有方法或属性


为了补充现有答案,Xcode 6.3和Swift 1.2在允许和不允许做的事情上更加严格。苹果公司已经收紧了swift,很可能你在做一些“不好”的事情,但之前版本的Xcode没有抓住。为了补充现有的答案,Xcode 6.3和swift 1.2在允许和不允许做的事情上更加严格。苹果公司已经收紧了swift,很可能你犯了一些“不好”的错误,但是之前版本的Xcode没有被理解。

你可以覆盖一个函数,但它必须被声明为公共函数。错误是

重写实例方法必须与其重写的声明一样可访问

下面是一个我一直致力于扩展UITextField的示例

override public func becomeFirstResponder() -> Bool

可以重写函数,但必须将其声明为公共函数。错误是

重写实例方法必须与其重写的声明一样可访问

下面是一个我一直致力于扩展UITextField的示例

override public func becomeFirstResponder() -> Bool

我已被转换为UITextfield子类中的扩展名。现在正确地工作。但现在扩展似乎无法覆盖或重新定义对象的方法。若要覆盖或重新定义,则需要子类化。扩展通过添加新的东西来“扩展”一个类。我已经在UITextfield子类中转换了扩展。现在正确地工作。但现在扩展似乎无法覆盖或重新定义对象的方法。若要覆盖或重新定义,则需要子类化。扩展通过添加新事物来“扩展”类。