zoukankan      html  css  js  c++  java
  • swift开发笔记23 BirthDays

    @escaping

     

    简单的介绍就是如果这个闭包是在这个函数结束前内被调用,就是非逃逸的即noescape。如果这个闭包是在函数执行完后才被调用,调用的地方超过了这函数的范围,所以叫逃逸闭包。

     

    ···未解决问题

    NSPredicate.init(format: "birthday is nil", <#T##args: CVarArg...##CVarArg#>)

     

    closure 闭包

     

    try contactStore.enumerateContacts(with: CNContactFetchRequest.init(keysToFetch: keys as! [CNKeyDescriptor]), usingBlock: { (contact, pointer) in

                            if contact.birthday != nil && contact.birthday?.month == self.currentlySelectedMonthIndex {

                                contacts.append(contact)

                            }

                        })

     

    if let homeEmail = HomeEmailTF.text {

                let homeEmail = CNLabeledValue.init(label: CNLabelHome, value: homeEmail as NSString)

                newContact.emailAddresses = [homeEmail]

            }

            let birthdayComponents = Calendar.current.dateComponents([Calendar.Component.year,Calendar.Component.month,Calendar.Component.day], from: datePick.date)

            newContact.birthday = birthdayComponents

     

    let saveRe = CNSaveRequest()

                saveRe.add(newContact, toContainerWithIdentifier: nil)

                try AppDelegate.appdelegate.contactStore.execute(saveRe)

     

     

    try contactStore.enumerateContacts(with: CNContactFetchRequest.init(keysToFetch: keys as! [CNKeyDescriptor]), usingBlock: { (contact, pointer) in })

     

    let predicate = CNContact.predicateForContacts(matchingName: self.tfield.text!)

                    let keys = [CNContactFormatter.descriptorForRequiredKeys(for: CNContactFormatterStyle.fullName),CNContactBirthdayKey,CNContactEmailAddressesKey] as [Any]

                    var contacts = [CNContact]()

                    var message: String!

                    

                    do {

                        contacts = try AppDelegate.appdelegate.contactStore.unifiedContacts(matching: predicate, keysToFetch: keys as! [CNKeyDescriptor])

                        if contacts.count == 0 {

                            message = "No contacts were found matching the given name."

                        }

                    } catch {

                        message = "Unable to fetch contacts."

                    }

  • 相关阅读:
    TCP/IP的确认号,序列号和超时重传的学习笔记
    Linux进程的虚拟内存
    Linux内存:物理内存管理概述
    Linux进程: task_struct结构体成员
    Linux进程:管理和调度
    Golang基础(8):go interface接口
    技术管理:团队建设
    从分布式一致性谈到CAP理论、BASE理论
    技术管理:项目管理概要
    [译]深入 NGINX: 为性能和扩展所做之设计
  • 原文地址:https://www.cnblogs.com/dengchaojie/p/8143625.html
Copyright © 2011-2022 走看看