小编Ste*_*all的帖子

在Swift中将Int转换为String

我正试图找出如何在Swift中Int投入一个String.

我想出了一个解决方法,使用NSNumber但我想知道如何在Swift中完成所有操作.

let x : Int = 45
let xNSNumber = x as NSNumber
let xString : String = xNSNumber.stringValue
Run Code Online (Sandbox Code Playgroud)

string int casting converter swift

532
推荐指数
14
解决办法
54万
查看次数

为UIAlertAction编写处理程序

我正在向UIAlertView用户展示一个,我无法弄清楚如何编写处理程序.这是我的尝试:

let alert = UIAlertController(title: "Title",
                            message: "Message",
                     preferredStyle: UIAlertControllerStyle.Alert)

alert.addAction(UIAlertAction(title: "Okay",
                              style: UIAlertActionStyle.Default,
                            handler: {self in println("Foo")})
Run Code Online (Sandbox Code Playgroud)

我在Xcode中遇到了很多问题.

文件说 convenience init(title title: String!, style style: UIAlertActionStyle, handler handler: ((UIAlertAction!) -> Void)!)

目前整个街区/封闭都有点过头了.任何建议都非常感谢.

uialertview ios swift uialertcontroller

92
推荐指数
6
解决办法
10万
查看次数

如何在swift中将子类NSManagedObject分配给var(而不是常量)

我有一个完整的Juice对象的实例变量数组,它是从子类中NSManagedObject获取的子类NSFetch.

我设置这样的UITableViewCell标题,没有问题:

let currentJuice = juiceList[indexPath.row]

cell.text = currentJuice.name
Run Code Online (Sandbox Code Playgroud)

但是,我正在尝试传递Juice视图控制器之间的实例.我声明了一个实例变量var selectedJuice = Juice()变量然后在willSelectRowAtIndexPathI put中:

 selectedJuice = juiceList[indexPath.row]
Run Code Online (Sandbox Code Playgroud)

此行引发错误CoreData: error: Failed to call designated initializer on NSManagedObject class,我无法弄清楚原因!我也不知道如何在Juice类中实现指定的init方法,如果有人可以帮助那个

core-data nsmanagedobject ios swift

2
推荐指数
1
解决办法
343
查看次数