国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Swift報錯:“‘nil‘ is incompatible with return type ‘User‘”

這篇具有很好參考價值的文章主要介紹了Swift報錯:“‘nil‘ is incompatible with return type ‘User‘”。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

func getUserById(userId: Int) -> User {
    if (userId != nil) {
        ...
    }
    return nil
}

上述代碼報了一個錯誤:“'nil' is incompatible with return type 'User'”,表示“nil”與返回類型“User”不兼容。

解決方案:

將返回值類型改為Optional類型User?

func getUserById(userId: Int) -> User? {
    if (userId != nil) {
        ...
    }
    return nil
}

同理,如果調(diào)用getUserById(nil)的時候也會報錯:“'nil' is not compatible with expected argument type 'Int'”

將參數(shù)類型改為Int?即可文章來源地址http://www.zghlxwxcb.cn/news/detail-701554.html

func getUserById(userId: Int?) -> User? {
    if (userId != nil) {
        ...
    }
    return nil
}

到了這里,關(guān)于Swift報錯:“‘nil‘ is incompatible with return type ‘User‘”的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • Node Sass version 8.0.0 is incompatible with ^4.0.0.

    Node Sass version 8.0.0 is incompatible with ^4.0.0.

    解決辦法:降低node版本,下載對應(yīng)node版本的npm install sass-loader@版本號 node-sass@版本號 --save-dev

    2024年02月11日
    瀏覽(17)
  • 【Node Sass version 8.0.0 is incompatible with ^4.0.0.問題解決】

    【Node Sass version 8.0.0 is incompatible with ^4.0.0.問題解決】

    在微信小程序Vue搭建安裝依賴后,重新運(yùn)行項目出現(xiàn)錯誤: 此時無法繼續(xù)運(yùn)行項目。 觀察package.json可以發(fā)現(xiàn)版本對應(yīng)情況: https://www.npmjs.com/package/node-sass 先卸載后安裝對應(yīng)版本。 重新運(yùn)行后無報錯。

    2024年02月11日
    瀏覽(19)
  • 關(guān)于yarn安裝時報“node“ is incompatible with this module的解決辦法

    關(guān)于yarn安裝時報“node“ is incompatible with this module的解決辦法

    在用vue寫一個h5頁面時,當(dāng)在用yarn安裝時,提示如下錯誤: The engine “node” is incompatible with this module. Expected version \\\"^14.18.0 || ^16.14.0 || =18. 我是使用命令忽略錯誤: 然后再安裝即可以成功: 安裝完之后項目可以正常啟動了

    2024年02月10日
    瀏覽(19)
  • 【vue】Node Sass version 6.0.1 is incompatible with ^4.0.0.

    npm run dev 提示錯誤:Node Sass version 6.0.1 is incompatible with ^4.0.0. node-sass 版本過高,卸載重裝低版本 1、卸載:npm uninstall node-sass 2、安裝:npm install node-sass@4.12.0 3、運(yùn)行:npm run dev 這是網(wǎng)上別人說的方法,實際上未能成功,以下是我的解決辦法: npm install sass-loader node-sass --save-

    2024年02月15日
    瀏覽(18)
  • The engine “node“ is incompatible with this module. Expected version

    The engine “node“ is incompatible with this module. Expected version

    vue項目用了yarn,yarn install后報錯如下: ** ** 執(zhí)行: 然后yarn install后成功。 在此記錄問題,如有需要修改的地方,還請不吝賜教。

    2024年02月12日
    瀏覽(20)
  • 15. 成功解決:java: Can‘t generate mapping method with primitive return type.

    15. 成功解決:java: Can‘t generate mapping method with primitive return type.

    ?? 個人主頁:水滴技術(shù) ?? 訂閱專欄:成功解決 BUG 合集 ?? 支持水滴: 點贊 ?? + 收藏 ? + 留言 ?? 今天啟動 SpringBoot 項目時,報了如下錯誤: java: Can\\\'t generate mapping method with primitive return type. 仔細(xì)一下,還不止這一個錯誤,錯誤截圖: 通過錯誤描述信息來看,應(yīng)該是

    2024年02月15日
    瀏覽(21)
  • 解決Error: Node Sass version 8.0.0 is incompatible with ^4.0.0.

    解決Error: Node Sass version 8.0.0 is incompatible with ^4.0.0.

    最近升級了node版本,導(dǎo)致與node sass版本不一致,項目編譯失敗,參照網(wǎng)上把版本都升級一致了,但是還是沒有解決問題。 后來參考一位朋友的做法,解決了該問題,具體如下: npm uninstall sass-loader node-sass npm install sass-loader@8.0.2 sass@1.26.5 ?--save-dev 執(zhí)行命令的完成后 啟動項目

    2024年02月12日
    瀏覽(21)
  • 解決Mapper method ‘com.xxx‘ attempted to return null from a method with a primitive return type (xxx)

    今天寫完 頁面按鈕排序 接口,如下代碼所示:

    2024年02月05日
    瀏覽(57)
  • The engine “node“ is incompatible with this module. Expected version 問題解決辦法

    The engine “node“ is incompatible with this module. Expected version 問題解決辦法

    安裝一個組件庫總是報錯: 手動右鍵刪除 node_modules 文件夾,清空了 npm 緩存: 發(fā)現(xiàn)還是不行。 后來在網(wǎng)上找到了解決方案:忽略錯誤。 終端輸入命令: 再重新安裝依賴,運(yùn)行項目就可以了:

    2024年02月12日
    瀏覽(22)
  • this is incompatible with sql_mode=only_full_group_by

    this is incompatible with sql_mode=only_full_group_by

    查看配置 select @@global.sql_mode 在sql命令行中輸入select @@sql_mode 能夠看到sql_mode配置,如果有ONLY_FULL_GROUP_BY,則需要修改 在mysql5.7.5后,ONLY_FULL_GROUP_BY是默認(rèn)選項,所以就會導(dǎo)致group by的問題 set sql_mode=‘復(fù)制去掉ONLY_FULL_GROUP_BY’; 當(dāng)然這樣處理也只是暫時的,要想永久的處理還得去

    2024年02月15日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包