gpt4 book ai didi

ios - NSObject 无法转换

转载 作者:行者123 更新时间:2023-11-28 12:55:55 24 4
gpt4 key购买 nike

我在以下代码行中遇到错误。由于这是我刚从github上下载的项目,https://github.com/HubSpot/BidHub-iOS我不确定这些行在做什么。

  let one = NSMutableAttributedString(string: "BID\n", attributes: bidAttrs as [NSObject : AnyObject] as [NSObject : AnyObject] )
one.appendAttributedString(NSMutableAttributedString(string: "$\(startAmount + incrementOne)", attributes: otherAttrs))
plusOneButton.setAttributedTitle(one, forState: .Normal)

let five = NSMutableAttributedString(string: "BID\n", attributes: bidAttrs as [NSObject : AnyObject] as [NSObject : AnyObject])
five.appendAttributedString(NSMutableAttributedString(string: "$\(startAmount + incrementFive)", attributes: otherAttrs))
plusFiveButton.setAttributedTitle(five, forState: .Normal)

let ten = NSMutableAttributedString(string: "BID\n", attributes: bidAttrs as [NSObject : AnyObject] as [NSObject : AnyObject])
ten.appendAttributedString(NSMutableAttributedString(string: "$\(startAmount + incrementTen)", attributes: otherAttrs))
plusTenButton.setAttributedTitle(ten, forState: .Normal)

错误如下

/Users/David/Desktop/iOS_app/Bid-Hub-app/iOS-app/BidHub-iOS-master/AuctionApp/BiddingVC/BiddingViewController.swift:104:109: Cannot convert value of type '[NSObject : AnyObject]' to expected argument type '[String : AnyObject]?'
/Users/DAVID/Desktop/iOS_app/Bid-Hub-app/iOS-app/BidHub-iOS-master/AuctionApp/BiddingVC/BiddingViewController.swift:112:109: Cannot convert value of type '[NSObject : AnyObject]' to expected argument type '[String : AnyObject]?'
/Users/DAVID/Desktop/iOS_app/Bid-Hub-app/iOS-app/BidHub-iOS-master/AuctionApp/BiddingVC/BiddingViewController.swift:108:110: Cannot convert value of type '[NSObject : AnyObject]' to expected argument type '[String : AnyObject]?'

所以就在你建议我删除多余的内容之前

as [NSObject : AnyObject]

已经试过了,报如下错误

/Users/David/Desktop/iOS_app/Bid-Hub-app/iOS-app/BidHub-iOS-master/AuctionApp/BiddingVC/BiddingViewController.swift:104:74: 'NSDictionary' is not implicitly convertible to '[NSObject : AnyObject]'; did you mean to use 'as' to explicitly convert?

编辑:

var bidAttrs = [NSFontAttributeName : UIFont(name: "Avenir-Light", size: 14.0)! , NSForegroundColorAttributeName: UIColor.grayColor()] as NSDictionary

最佳答案

您不需要将 bidAttrs 转换为 NSDictionary,所以只需这样做:

var bidAttrs = [NSFontAttributeName : UIFont(name: "Avenir-Light", size: 14.0)! , NSForegroundColorAttributeName: UIColor.grayColor()]
let one = NSMutableAttributedString(string: "BID\n", attributes: bidAttrs )

但是,如果您出于某种原因需要它成为 NSDictionary,您的转换应该如下所示:

let one = NSMutableAttributedString(string: "BID\n", attributes: bidAttrs as? [String : AnyObject] )

关于ios - NSObject 无法转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35061834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com