【问题标题】:Error: Type of expression is ambiguous without more context Using Paper Onboarding错误:在没有更多上下文的情况下,表达类型不明确
【发布时间】:2021-01-26 03:15:26
【问题描述】:

我正在尝试为我的应用程序使用纸质入门,但我总是收到错误消息“表达式类型不明确,没有更多上下文”。我正在使用 Xcode 12。除了函数“func onboardingItemsCount”的返回部分外,其他任何地方都没有错误。我对 xcode 相当陌生,所以我不确定我做错了什么。任何帮助,将不胜感激。以下是部分代码:

func onboardingItemsCount() -> Int {
    return 3
}

func onboardingItem(at index: Int) -> OnboardingItemInfo {
    
    let backgroundColorOne = UIColor(red: 217/255, green: 72/255, blue: 89/255, alpha: 1)
    let backgroundColorTwo = UIColor(red: 106/255, green: 166/255, blue: 211/255, alpha: 1)
    let backgroundColorThree = UIColor(red: 168/255, green: 200/255, blue: 78/255, alpha: 1)
    
    let titleFont = UIFont(name: "AvenirNext-Bold", size: 24)!
    let descriptionFont = UIFont(name: "AvenirNext-Regular", size: 18)

    return [
        
         OnboardingItemInfo(informationImage: "image_1",
                                       title: "Healthy + Food",
                                 description: "Quickly search and add healthy foods",
                                    pageIcon: "",
                                       color: backgroundColorOne,
                                  titleColor: UIColor.white,
                            descriptionColor: UIColor.white,
                                   titleFont: titleFont,
                             descriptionFont: descriptionFont),
                                
        
         OnboardingItemInfo(informationImage: "image_2",
                                        title: "Healthy + Cart",
                                  description: "Add items to your cart",
                                     pageIcon: "",
                                        color: backgroundColorTwo,
                                   titleColor: UIColor.white,
                             descriptionColor: UIColor.white,
                                    titleFont: titleFont,
                              descriptionFont: descriptionFont),
        
        OnboardingItemInfo(informationImage: "image_3",
                                     title: "Healthy + Delivery",
                               description: "View Markets in your area",
                                  pageIcon: "",
                                     color: backgroundColorThree,
                                titleColor: UIColor.white,
                          descriptionColor: UIColor.white,
                                 titleFont: titleFont,
                           descriptionFont: descriptionFont)

     ] [index]            (Error: Type of expression is ambiguous without more context)
    
     }
}

【问题讨论】:

    标签: swift swift5 xcode12


    【解决方案1】:

    请你试试这个

    let descriptionFont = UIFont(name: "AvenirNext-Regular", size: 18)!
    

    而不是

    let descriptionFont = UIFont(name: "AvenirNext-Regular", size: 18)
    

    【讨论】:

    • 谢谢。解决了!
    猜你喜欢
    • 2022-11-23
    • 2019-02-01
    • 2022-11-18
    • 2015-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多