<commit_before>//  Contagged.swift
//  SkipChat
//
//  Created by <NAME> on 1/17/15.
//  Copyright (c) 2015 SkipChat. All rights reserved.
//
import AddressBook
import AddressBookUI
import UIKit

protocol ContaggedPickerDelegate {
    func peoplePickerNavigationControllerDidCancel()
    func personSelected(person: SwiftAddressBookPerson!)
}

protocol ContaggedUnknownPersonDelegate {
    func didResolveToPerson(person: SwiftAddressBookPerson!)
}

class ContaggedManager: NSObject, ABPeoplePickerNavigationControllerDelegate, ABUnknownPersonViewControllerDelegate {
    
    var pickerDelegate : ContaggedPickerDelegate?
    var unknownPersonDelegate : ContaggedUnknownPersonDelegate?
    var viewController : UIViewController?
    
    // MARK: Authorization Methods
    class func getAuthorizationStatus() -> ABAuthorizationStatus {
        return SwiftAddressBook.authorizationStatus()
    }
    
    func requestAuthorizationWithCompletion(completion: (Bool, CFError?) -> Void ) {
        swiftAddressBook?.requestAccessWithCompletion(completion)
    }

    // MARK: People Picker Methods
    func pickContact(fieldName: String) -> Void {
        let picker = ABPeoplePickerNavigationController()
        picker.peoplePickerDelegate = self
        
        if picker.respondsToSelector(Selector("predicateForEnablingPerson")) {
            // urls.filter({$0.label == fieldName}).count > 0
            picker.predicateForEnablingPerson = NSPredicate(format: "ANY urls.fieldName = %@", fieldName)
        }
        
        viewController?.presentViewController(picker, animated: true, completion: nil)
    }
    
    func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!,
        didSelectPerson person: ABRecordRef!) {
        pickerDelegate?.personSelected(swiftAddressBook?.personWithRecordId(ABRecordGetRecordID(person)))
    }
    
    func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, shouldContinueAfterSelectingPerson person: ABRecordRef!) -> Bool {
        peoplePickerNavigationController(peoplePicker, didSelectPerson: person)
        peoplePicker.dismissViewControllerAnimated(true, completion: nil)
        return false;
    }<commit_msg>fixed contact picker predicate<commit_after>//  Contagged.swift
//  SkipChat
//
//  Created by <NAME> on 1/17/15.
//  Copyright (c) 2015 SkipChat. All rights reserved.
//
import AddressBook
import AddressBookUI
import UIKit

protocol ContaggedPickerDelegate {
    func peoplePickerNavigationControllerDidCancel()
    func personSelected(person: SwiftAddressBookPerson!)
}

protocol ContaggedUnknownPersonDelegate {
    func didResolveToPerson(person: SwiftAddressBookPerson!)
}

class ContaggedManager: NSObject, ABPeoplePickerNavigationControllerDelegate, ABUnknownPersonViewControllerDelegate {
    
    var pickerDelegate : ContaggedPickerDelegate?
    var unknownPersonDelegate : ContaggedUnknownPersonDelegate?
    var viewController : UIViewController?
    
    // MARK: Authorization Methods
    class func getAuthorizationStatus() -> ABAuthorizationStatus {
        return SwiftAddressBook.authorizationStatus()
    }
    
    func requestAuthorizationWithCompletion(completion: (Bool, CFError?) -> Void ) {
        swiftAddressBook?.requestAccessWithCompletion(completion)
    }

    // MARK: People Picker Methods
    func pickContact(fieldName: String) -> Void {
        let picker = ABPeoplePickerNavigationController()
        picker.peoplePickerDelegate = self
        
        if picker.respondsToSelector(Selector("predicateForEnablingPerson")) {
            picker.predicateForEnablingPerson = NSPredicate(format: "SUBQUERY(%K, $url, $url.label = %@).@count > 0", ABPersonUrlAddressesProperty, fieldName)
        }
        
        viewController?.presentViewController(picker, animated: true, completion: nil)
    }
    
    func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!,
        didSelectPerson person: ABRecordRef!) {
        pickerDelegate?.personSelected(swiftAddressBook?.personWithRecordId(ABRecordGetRecordID(person)))
    }
    
    func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, shouldContinueAfterSelectingPerson person: ABRecordRef!) -> Bool {
        peoplePickerNavigationController(peoplePicker, didSelectPerson: person)
        peoplePicker.dismissViewControllerAnimated(true, completion: nil)
        return false;
    }
{'fraction_non_alphanumeric': 0.07699194270367055, 'fraction_numerical': 0.004700089525514772, 'mean_word_length': 4.220794392523365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '206755', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1086, 'n_words': 228}