小编Ste*_*rta的帖子

Swift 1.2不使用相同的函数名和不同的参数

我有2个具有相同名称但不同参数的函数.

第一个接受一个接受2个双精度并返回1的函数作为参数.

第二个接受一个接受1 double并返回1的函数作为参数.这适用于在Xcode 6.1.1上测试的Swift 1.1,但是在Swift 1.2中,在Xcode 6.4(beta)上测试过,这不起作用并且给我这个错误:

使用Objective-C选择器'performOperation:'的方法'performOperation'与使用相同Objective-C选择器的先前声明冲突

我能做些什么才能发挥作用,为什么会这样呢?我知道我可以用另一种方式做平方根然后就在这里,但我想知道问题是什么.

编辑

 @IBAction func operate(sender: UIButton) {
        let operation = sender.currentTitle!
        if userIsInMiddleOfTypingANumber{
            enter()
        }
        switch operation{
        case "×" : performOperation {$0 * $1}
        case "÷" : performOperation {$1 / $0}
        case "+" : performOperation {$0 + $1}
        case "?" : performOperation {$1 - $0}
        case "?" : performOperation {sqrt($0)}
        default : break
        }
    }

    func performOperation(operation : (Double,Double) -> Double){
        if operandStack.count >= 2{
            displayValue = operation(operandStack.removeLast(),operandStack.removeLast())
            enter()
        }
    } …
Run Code Online (Sandbox Code Playgroud)

swift

6
推荐指数
1
解决办法
1262
查看次数

突出显示UILabel中的子字符串

我可以;突出显示一个子串.这就是我所做的(是一个"重复"的问题):

这是我需要将它投射到NSRange的地方

for user in tweet.userMentions
{          
    let userName = user.keyword
    if let startIndex = tweetTextLabel.text?.rangeOfString("@")?.startIndex
    {
        let range = startIndex...userName.endIndex
        var atrString = NSMutableAttributedString(string:tweetTextLabel.text!)
        atrString.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: range as? NSRange)
        tweetTextLabel.attributedText = atrString
    }
}
Run Code Online (Sandbox Code Playgroud)

我能做什么??也许那里有另一个功能,我快速使用swift 1.1,iOS 8.1 SDK

更新 仍然没有高调文本

 for user in tweet.userMentions{

                let text = tweetTextLabel.text!
                let nsText = text as NSString
                let textRange = NSMakeRange(0, nsText.length)
                let attributedString = NSMutableAttributedString(string: nsText)

                nsText.enumerateSubstringsInRange(textRange, options: NSStringEnumerationOptions.ByWords, { (substring, substringRange, enclosingRange, stop) -> () in

                    if …
Run Code Online (Sandbox Code Playgroud)

twitter uitableview ios swift

3
推荐指数
2
解决办法
2379
查看次数

标签 统计

swift ×2

ios ×1

twitter ×1

uitableview ×1