缓慢编译 swift 源文件 - Xcode 8 swift 3
Slow compiling swift source file - Xcode 8 swift 3
我刚刚将我的项目更新为 Xcode 8
和 Swift 3
。
我的问题是我的应用程序编译特定 class 非常非常慢,如下:
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
]
}
如何解决我的问题?感谢您的帮助。
这个方法好慢,所以我找到了解决办法。
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
]
}
感谢大家的帮助
Swift 3 像这样:
如果是几种类型
var dict: [String: Any] = [
"book_key": true,
"book_title": "Yannick",
"book_author": "Test",
"book_price": 123
]
或者如果你 return 很多像这样的字符串
var dict: [String: String] = [
"book_key": "true",
"book_author": "Yannick",
"book_price": "123",
"book_publisher": "Yannick",
"page_count": "123"
]
我刚刚将我的项目更新为 Xcode 8
和 Swift 3
。
我的问题是我的应用程序编译特定 class 非常非常慢,如下:
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
]
}
如何解决我的问题?感谢您的帮助。
这个方法好慢,所以我找到了解决办法。
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
]
}
感谢大家的帮助
Swift 3 像这样:
如果是几种类型
var dict: [String: Any] = [
"book_key": true,
"book_title": "Yannick",
"book_author": "Test",
"book_price": 123
]
或者如果你 return 很多像这样的字符串
var dict: [String: String] = [
"book_key": "true",
"book_author": "Yannick",
"book_price": "123",
"book_publisher": "Yannick",
"page_count": "123"
]