2015-08-14 64 views
0

我正在編寫一個應用程序,它將時間符號與一段時間進行比較,然後獲取扇區數量,然後返回一個責任限制。運營商只允許在全球範圍內

例如,對於兩個部門在上一個0035標誌返回1030

此作品在我的遊樂場確定責任限額,但在轉移到Xcode中帶來了一些編譯器錯誤。

開頭「操作員只能在全局範圍內」。

任何人都可以點我在正確的方向?

這是我到目前爲止的代碼:

let dateMaker = NSDateFormatter() 
dateMaker.dateFormat = "HHmm" 

let FTL1 = dateMaker.dateFromString("0800")! 
let FTL2 = dateMaker.dateFromString("1259")! 
let FTL3 = dateMaker.dateFromString("1300")! 
let FTL4 = dateMaker.dateFromString("1759")! 
let FTL5 = dateMaker.dateFromString("1800")! 
let FTL6 = dateMaker.dateFromString("2159")! 
let FTL7 = dateMaker.dateFromString("2200")! 
let FTL8 = dateMaker.dateFromString("2359")! 
let FTL9 = dateMaker.dateFromString("0000")! 
let FTL10 = dateMaker.dateFromString("0759")! 

let SO = dateMaker.dateFromString("0035") 
var sect = 2 

func <(lhs: NSDate, rhs: NSDate) -> Bool 
{ 
    return lhs.compare(rhs) == .OrderedAscending 
} 

func >(lhs: NSDate, rhs: NSDate) -> Bool 
{ 
    return lhs.compare(rhs) == .OrderedDescending 
} 


if SO! == FTL1 || SO! == FTL2 || SO! > FTL1 && SO! < FTL2 { 

    if sect == 1 { 
    let FTL = "1400" 
    } 
    if sect == 2 { 
     let FTL = "1315" 
    } 
    if sect == 3 { 
     let FTL = "1230" 
    } 
} 
if SO! == FTL3 || SO! == FTL4 || SO! > FTL3 && SO! < FTL4 { 

    if sect == 1 { 
     let FTL = "1300" 
    } 
    if sect == 2 { 
     let FTL = "1215" 
    } 
    if sect == 3 { 
     let FTL = "1130" 
    } 
} 
if SO! == FTL5 || SO! == FTL6 || SO! > FTL5 && SO! < FTL6 { 

    if sect == 1 { 
     let FTL = "1200" 
    } 
    if sect == 2 { 
     let FTL = "1115" 
    } 
    if sect == 3 { 
     let FTL = "1030" 
    } 
} 

if SO! == FTL7 || SO! == FTL8 || SO! > FTL7 && SO! < FTL8 { 

    if sect == 1 { 
     let FTL = "1100" 
    } 
    if sect == 2 { 
     let FTL = "1030" 
    } 
    if sect == 3 { 
     let FTL = "0930" 
    } 
} 

if SO! == FTL9 || SO! == FTL10 || SO! > FTL9 && SO! < FTL10 { 

    if sect == 1 { 
     let FTL = "1100" 
    } 
    if sect == 2 { 
     let FTL = "1030" 
    } 
    if sect == 3 { 
     let FTL = "0930" 
    } 
} 
+2

的是一個類定義中的代碼?在這種情況下 - 如錯誤消息所示 - 必須將*運算符*定義移到類之外。 –

+0

感謝馬丁R.這似乎已經修復它! – smi6086

回答

1

你應該寫代碼淘汰類

class NewObject { 
} 
func >(lhs: NSDate, rhs: NSDate) -> Bool 
{ 
    return lhs.compare(rhs) == .OrderedDescending 
}