【问题标题】:xcode issue with apple swift [duplicate]苹果swift的xcode问题[重复]
【发布时间】:2014-07-21 13:22:56
【问题描述】:

我正在测试 swift 语言。 突然 xcode 终止而没有显示错误。 但收到以下消息:

源工具包服务终止编辑器功能暂时受限

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.myfunction()

        //ViewController.classFunc()

        //myfunctionWithArg()
        //myfunctionWithArg(name: "hashim")

        //learnSwitch()

        self.learnClosure()

        /*
        let anInstance = MyClass()
        anInstance.aFunction()

        let someVehicle = Vehicle()
        println(someVehicle.description)

        someVehicle.description = "test"

        let aCycle = Cycle()
        println(aCycle.description)
*/
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }




       func learnClosure(){

        let retValue = jediGreet("old friend")
        println(retValue)
        println(retValue.0)
        println(retValue.1)

        let train = jediTrainer("hashim")
        println(train("new programming swift", 3))

        println((jediTrainer("hashim"))("Obi Wan", 3))

        var names = ["fashim","hashim","ashim","bashim","cashim","dashim"]

        sort(names, { (s1:String,s2:String)-> Bool in
            println("test arg1:\(s1), arg2:\(s2)")
            return s1>s2 }  )

        sort(names, >)
           println(sort(names, <))




        /*
        let myadd = { (sum:Int,number:Int)->Int in

            return (sum + number)

        }
        */

    //    let myadd = {  ($0 + $1) }


    //    println("sum is \(myadd(3,4))")

        let padawans = ["Knox", "Avitla", "Mennaus"]

       println( padawans.map({
            (padawan: String) -> String in
            "\(padawan) has been trained!"
            }))


        var numbers = [10,1,20,123,50]

        println("before \(numbers)")
        mySort(numbers,{
            (num1:Int,num2:Int) -> Bool in

            return num1 > num2

            })
  println("after \(numbers)")

    }

    func mySort( numbers:Int[],compare:((Int,Int)->Bool))
    {
        //Write your login  to sort numbers using comparator method
        var tmp:Int
        var n = numbers.count

        for(var i=0;i<n;i++)
        {
            for(var j=0;j<n-i-1;j++)
            {
                if(numbers[j] > numbers[j+1])
                {
                    tmp=numbers[j];
                    numbers[j]=numbers[j+1];
                    numbers[j+1]=tmp;
                }
            }
        }
    }



    func repeat (count:Int,task:()->()){

        for i in 0..count{

            task()
        }

    }


    func jediGreet(String) -> (farewell: String, mayTheForceBeWithYou: String) {
        return ( "name" , " May the (ability) be with you.")
    }

    func jediTrainer (caller:String) -> ((String, Int) -> String) {
        func train(name: String, times: Int) -> (String) {
            return "\(name) has been trained in the Force \(times) times calling \(caller)"
        }
        return train
    }


}

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    这可能是由于 xcode 中的几个原因(只是因为 swift 仍处于测试阶段)。在您的情况下,只需注释行 // println(train("new programming swift", 3)).如果你想获得这个功能,把那行代码分成两行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-03
      • 1970-01-01
      • 2016-10-02
      • 1970-01-01
      • 2021-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多