swift2 x不能使用函式過載的問題

2021-07-10 13:09:30 字數 1032 閱讀 3358

最近在看史丹福大學ios開發教程時,一邊看一邊跟著敲**,結果發現函式不能過載:

錯誤內容是:

method 『performoperation』 with objective-c selector

『performoperation:』 conflicts with previous declaration with the same

objective-c selector

最後在這個部落格找到了原因:

這是因為你的viewcontroller 繼承了uiviewcontroller.而uiviewcontroller

繼承自oc的nsobject. 在swift 中被修飾成@objc class.

那麼就必須要遵循oc的selector,在oc中是不支援方法過載的。所以會報上面的錯誤。這跟使用的xcode版本有關,白鬍子老頭使用的版本較低,而我使用的是xcode7,已經是swift2了,與之前有好多不同的地方。

在compiler error: method with objective-c selector conflicts with previous declaration with the same objective-c selector找到了解決辦法:

在xcode7的swift2中有兩種解決方法:

一種是使用@objc(newnamemethod:),如下

func methodone(par1, par2)

@objc(methodtow:) func methodone(par1)

另一種是使用 @nonobjc,如下:

func methodone()

@nonobjc func methodone()

Mysql裡不能使用聚合函式

採取的第一種方式 記錄一下關於mysql的乙個報錯問題解決方案 in aggregated query without group by,expression 1 of select list contains nonaggregated column yunva changke.u.user id...

什麼時候不能使用箭頭函式

js 中物件方法的定義方式是在物件上定義乙個指向函式的屬性,當方法被呼叫的時候,方法內的 this 就會指向方法所屬的物件。1.1 定義字面量方法 因為箭頭函式的語法很簡潔,可能不少同學會忍不住用它來定義字面量方法,比如下面的例子 const calculator console.log this ...

字串翻轉 不能使用系統函式

思想 定義頭尾兩個指標 交換頭尾指標的資料 字串翻轉 char strrev char str 定義char陣列指標 char start str char end str while end 0 交換頭和尾的值 char temp end 去除 0的位置 while start end retur...