我刚刚将我的项目更新为Xcode 8
和Swift 3
。
我的问题是我的应用程序编译特定类的速度非常慢,如下所示:
var dict: Dictionary<String, AnyObject> {
return [
"book_key": book_key as AnyObject,
"book_title": book_title as AnyObject,
"book_author": book_author as AnyObject,
"book_price": book_price as AnyObject,
"book_publisher" : book_publisher as AnyObject,
"page_count": page_count as AnyObject,
"book_description": book_description as AnyObject,
"book_urlImage" : book_urlImage as AnyObject,
"book_urlImage2": book_urlImage2 as AnyObject,
"user_key": user_key as AnyObject,
"user_name": user_name as AnyObject,
"user_tag_login" : user_tag_login as AnyObject,
"onGoingNegotiations" : onGoingNegotiations as AnyObject,
"other_user_key": other_user_key as AnyObject,
"other_tag_login": other_tag_login as AnyObject,
"book_condition": book_condition as AnyObject,
"timestamp": timestamp! as AnyObject
]
}
如何解决我的问题?谢谢你的帮助。
答案 0 :(得分:1)
方法太慢,所以我找到了解决方案。
timestamp
NSNumber将被投射为String
,因此该方法可以再次完美运行。
var dict: Dictionary<String, String> {
return [
"book_key": book_key,
"book_title": book_title,
"book_author": book_author,
"book_price": book_price,
"book_publisher" : book_publisher,
"page_count": page_count,
"book_description": book_description,
"book_urlImage" : book_urlImage,
"book_urlImage2": book_urlImage2,
"user_key": user_key,
"user_name": user_name,
"user_tag_login" : user_tag_login,
"onGoingNegotiations" : onGoingNegotiations,
"other_user_key": other_user_key,
"other_tag_login": other_tag_login,
"book_condition": book_condition,
"timestamp": timestamp
]
}
感谢大家的帮助
答案 1 :(得分:0)
Swift 3 喜欢这样:
如果有几种类型
var dict: [String: Any] = [
"book_key": true,
"book_title": "Yannick",
"book_author": "Test",
"book_price": 123
]
或者如果你像这样返回很多字符串
var dict: [String: String] = [
"book_key": "true",
"book_author": "Yannick",
"book_price": "123",
"book_publisher": "Yannick",
"page_count": "123"
]