I was testing swift language. Suddenly xcode terminated without showing error. But got the following message:
Source kit service terminated editor functionality temporarily limited
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
}
}
This can happen due to several reason in xcode (it is just because swift is still in beta) . In your case just comment the line // println(train("new programming swift", 3)). If you want to get this functionality split that line of code into two
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With