我有一个Swift应用程序。为了进行填充,我编写了以下代码:
class TextField: UITextField {
let padding = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 5)
override open func textRect(forBounds bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, padding)
}
override open func placeholderRect(forBounds bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, padding)
}
override open func editingRect(forBounds bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, padding)
}
Run Code Online (Sandbox Code Playgroud)
但是今天我将项目转换为Swift 4.2,现在出现错误:
'UIEdgeInsetsInsetRect'已被实例方法'CGRect.inset(by :)'取代
我该如何解决?
我需要在后台模式下使用相机连续拍摄图像.但根据苹果文档,我们无法在后台模式下使用相机.是否有任何替代解决方案,无需打开应用程序即可获取相机.我的任务是,当用户点击一个按钮时,应该关闭应用程序并连续拍摄图像.你能不能指导我完成这项任务?
我从服务器获取JSON数据.
这是我的代码:
let myPTYPEIntegerValue : NSInteger? = (allData as! NSDictionary ).value(forKey: "PTYPE") as? NSInteger
if myPTYPEIntegerValue != nil{
help.myPTYPE = String.init(describing: myPTYPEIntegerValue)
}
let myIdIntegerValue : NSInteger? = (allData as! NSDictionary ).value(forKey: "ID") as? NSInteger
if myIdIntegerValue != nil{
help.myId = String.init(describing: myIdIntegerValue)
}
let jsonIDIntegerValue : NSInteger? = (allData as! NSDictionary ).value(forKey: "UID") as? NSInteger
if jsonIDIntegerValue != nil{
help.myUID = String.init(describing: jsonIDIntegerValue!)
print(help.myUID)
}
Run Code Online (Sandbox Code Playgroud)
但它正在显示
Optional(3)
Optional(2930)
Optional(238)
Run Code Online (Sandbox Code Playgroud)
如何在这里打开可选项?我的代码有什么问题?
我有一个字符串: "mocktail, wine, beer"
我怎样才能将其转换为:"mocktail", "wine", "beer"?