如何在sw中将anyobject类型转换为int
问题描述:
我在这样的字典数组中搜索一个键。
我得到了正确的结果值。但我的问题是我想将此结果转换为Int值。我尝试了几种方法,但没有帮助。
这是我试过的一种方式,但这个数字检查条件不成功。
我该怎么做?请帮我。谢谢
我尝试过:
I am searching a key in an Array of dictionary like this.
I am getting the correct value for result. But my problem is I want to convert this result in to Int value. I tried several ways but didnt help.
This is one way I tried,, but this number checking condition doesn't get true.
How can I do this? Please help me. Thanks
What I have tried:
if let result = self.lasrIDArray.flatMap({$0["\(self.selectedTitle)"]}).first {
print("-------RESULT------\(result)") //->title of the other
if let number=result as? NSNumber
{
let tag=number.integerValue
let currentScroll=self.view.viewWithTag(Int(api.selectedCatID)!) as! UIScrollView
let lastImgVw=currentScroll.viewWithTag(tag) as! UIImageView
print("-------LASTIMG ORIGIN------\(lastImgVw.frame.origin.y)")
}
答
0 [ \(self.selectedTitle)]})。first {
print( -------结果------ \(结果)) // - >其他的标题
if 让number =结果为? NSNumber
{
let tag = number.integerValue
let currentScroll = self.view.viewWithTag(Int(api.selectedCatID)!)as! UIScrollView
让lastImgVw = currentScroll.viewWithTag(tag)为! UIImageView
print( ------- LASTIMG ORIGIN ------ \( lastImgVw.frame.origin.y))
}
0["\(self.selectedTitle)"]}).first { print("-------RESULT------\(result)") //->title of the other if let number=result as? NSNumber { let tag=number.integerValue let currentScroll=self.view.viewWithTag(Int(api.selectedCatID)!) as! UIScrollView let lastImgVw=currentScroll.viewWithTag(tag) as! UIImageView print("-------LASTIMG ORIGIN------\(lastImgVw.frame.origin.y)") }