我正在尝试添加一个UITapGestureUIButton,以便在点击时触发一个函数.我正在使用Swift 3并且收到一些错误:
由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [SwiftRunner.ViewController tapBlurButton]:无法识别的选择器发送到实例0x149e07610'
这大致是我所拥有的:
// Swift 3
import UIKit
class ViewController {
@IBOutlet weak var qsBlurButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
let tapGesture = UITapGestureRecognizer(target: self, action: Selector(("tapBlurButton")))
qsBlurButton.addGestureRecognizer(tapGesture)
}
func tapBlurButton(sender: UITapGestureRecognizer) {
print("Please Help!")
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个符合NSCoding协议的简单对象.
import Foundation
class JobCategory: NSObject, NSCoding {
var id: Int
var name: String
var URLString: String
init(id: Int, name: String, URLString: String) {
self.id = id
self.name = name
self.URLString = URLString
}
// MARK: - NSCoding
required init(coder aDecoder: NSCoder) {
id = aDecoder.decodeObject(forKey: "id") as? Int ?? aDecoder.decodeInteger(forKey: "id")
name = aDecoder.decodeObject(forKey: "name") as! String
URLString = aDecoder.decodeObject(forKey: "URLString") as! String
}
func encode(with aCoder: NSCoder) {
aCoder.encode(id, forKey: "id")
aCoder.encode(name, forKey: "name")
aCoder.encode(URLString, forKey: …Run Code Online (Sandbox Code Playgroud) 这是我应该如何传递Date到NSPredicate.init(format predicateFormat: String, arguments argList: CVaListPointer).
let endDate = Date()
NSPredicate(format: "endDate == %@", endDate as CVarArg)
Run Code Online (Sandbox Code Playgroud)
它看起来有点笨拙,我怀疑我做错了什么.
如何设置UIButtonXcode中的背景颜色?
我在布局属性中看到属性Background和Image但我无法在这两个中设置任何内容.(我只能在两种颜色中设置图像)
我有一个UIDatePicker显示日,月和年.但我不知道如何获得这些参数.
那么UIDatePicker使用Swift 3 获得日,月和年的最佳方法是什么?
我想得到这样的当前时间戳:
636110767775716756?
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时:
NSDate().timeIntervalSince1970
Run Code Online (Sandbox Code Playgroud)
它返回一个这样的值:
1475491615.71278
Run Code Online (Sandbox Code Playgroud)
我有以下警报方法.
static func notifyUser(_ title: String, message: String) -> Void
{
let alert = UIAlertController(title: title,
message: message,
preferredStyle: UIAlertControllerStyle.alert)
let cancelAction = UIAlertAction(title: "OK",
style: .cancel, handler: nil)
alert.addAction(cancelAction)
self.presentViewController(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
我得到一个错误,说是有一个额外的参数animated的presentViewController方法,但是我把它拿出来的时候,它仍然没有清除错误,然后有人告诉我completion是一个额外的参数.
let us = "http://example.com"
let range = us.rangeOfString("(?<=://)[^.]+(?=.com)", options:.RegularExpressionSearch)
if range != nil {
let found = us.substringWithRange(range!)
print("found: \(found)") // found: example
}
Run Code Online (Sandbox Code Playgroud)
此代码substring在Swift 2中的反斜杠和点com之间进行提取.我搜索了Internet,我发现rangeOfString改为range().
但我仍然无法使代码在Swift 3.0中运行.你可以帮帮我吗 ?
编辑:我正在使用swift 3 07-25 build.
所以我有这个代码:
if view.isKindOfClass(classType){...}
Run Code Online (Sandbox Code Playgroud)
这在Swift 2中运行良好,但是现在我在Swift 3中,我得到了这个错误:
类型的值UIView没有成员isKindOfClass
我如何在Swift 3中测试它?
我试图在swift 3.0中使用对象执行选择器
我有一个选择器,有一个参数
func imageSelected(aImage : UIImage)
我称之为
viewC.perform(Selector.init("imageSelected:"), with: image, afterDelay: 0.1)
但应用程序崩溃时出现错误,未定义选择器.