我发现的大部分内容都是使用AddressBook而不是新的Contacts.我正在尝试将所有用户联系人的姓名和电话号码显示在应用程序的tableview中.然后将所有这些数字带入一个API,该API交叉引用是否已经有任何帐户,因此我可以在那些旁边显示"添加朋友"按钮.是否有一种快速简便的方法来请求权限然后使用Swift3将所有联系人放入一个数组并与iOS9和更新版本兼容?
我不想找到或添加联系人,我只想要一个数组中的所有数字和名称
我试图在用户点击本地通知后呈现AlertView.AlertView具有取消或确定选项.
extension ViewController:UNUserNotificationCenterDelegate{
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("Tapped in notification")
if(defaults.object(forKey: "alertOn") != nil){
// Create the alert controller
let alertController = UIAlertController(title: "Some text", message: "Some text again", preferredStyle: .alert)
// Create the actions
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) {
UIAlertAction in
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) {
UIAlertAction in
}
// Add the actions
alertController.addAction(okAction)
alertController.addAction(cancelAction)
// Present the controller
self.present(alertController, animated: true, …Run Code Online (Sandbox Code Playgroud) 我花了差不多一个星期尝试不成功.如何获取当月的最后日期.例如,如果它是非闰年的二月,那么该月的最后一个日期必须是28.如何获得'28'.另一个例子:如果是1月那么最后一个日期必须是'31'
我知道对于Web Firebase API,有一个.push()选项可以保证条目按照它们插入数据库的顺序.但是,使用Swift添加数据的唯一方法是使用.set()和.updateChildValues()方法.
是否有类似于.push()Swift的内容,我可以确保我的数据按插入顺序显示?
我正在UIViewcontroller使用alertmessage扩展程序进行使用RXSwift.
// UIViewController+Alertmessage
public func observeAlertMessageSignal(alert: Observable<String>) {
let disposeBag = DisposeBag()
alert.observeOn(MainScheduler.instance)
.subscribe(onNext: { message in
self.alertCustomTransitionDelegate = CustomTransitioningDelegate()
let viewModel = AlertViewModel(message: message)
let storyboard = UIStoryboard(name: "Alert", bundle: nil)
let viewController = storyboard.instantiateInitialViewController() as! AlertViewController
viewController.viewModel = viewModel
viewController.delegate = self
viewController.modalPresentationStyle = .custom
viewController.transitioningDelegate = self.alertCustomTransitionDelegate
self.present(viewController, animated: true, completion: nil)
}).addDisposableTo(disposeBag)
}
// ViewModel
--> Declaration of alertObservable in viewModel
var alertObservable = PublishSubject<String>()
--> usage of observable:
transportResponse = active.asObservable() …Run Code Online (Sandbox Code Playgroud) 我有一个UITableViewController的问题:表视图显示但是只有在触摸单元格时才会调用didDeselectRowAt.有没有人看到这个代码的问题?
import UIKit
import MediaPlayer
class LibraryTableViewController: UITableViewController{
let mediaItems = MPMediaQuery.songs().items
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return mediaItems!.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = mediaItems?[indexPath.row].title
return cell
}
override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
print("table item selected")
OperationQueue.main.addOperation{
self.performSegue(withIdentifier: "showPlayer", sender: self)
}
}
override func …Run Code Online (Sandbox Code Playgroud) 在Swift 2中,我们可以轻松添加保护声明的位置
guard let varA = 1 where varB == 2 else {return}
Run Code Online (Sandbox Code Playgroud)
但是where在swift 3中删除了,我怎么能在Swift 3中做到这一点?
我有一个使用以下内容初始化的Swift 3数组:
var foo: [String] = []
在我的一个递归调用的方法中,我试图将一个字符串转换为一个字符数组,但是附加这些字符而不是直接赋值foo.所以这将编译:
self.foo = text.characters.map { String($0) }
但是下面的休息:
self.foo.append(text.characters.map { String($0) })
它产生的错误是: 'map' produces '[T]', not expected contextual result type 'String'
接近这个的正确方法是什么?
我有一个UIButton,它有四个子UILabel,包含有关按钮功能的信息.当我单击按钮的中心时,操作不会触发,因为它被UILabel阻挡,但当我单击按钮外部时,操作会触发.有没有办法阻止UILabels阻止动作射击?