From ad685d1f12617047a6f251c575f8a36a70f4b9b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Payche=CC=80re?= Date: Tue, 17 Nov 2015 11:46:33 +0100 Subject: [PATCH 1/4] Migrated to Swift 2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Paychère --- Contacts/ABPerson.swift | 6 +++--- Contacts/String.swift | 2 +- Contacts/main.swift | 2 +- Gravatar2Contacts.xcodeproj/project.pbxproj | 2 ++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Contacts/ABPerson.swift b/Contacts/ABPerson.swift index 88d30a0..b044fb3 100644 --- a/Contacts/ABPerson.swift +++ b/Contacts/ABPerson.swift @@ -11,15 +11,15 @@ import AddressBook extension ABPerson { func firstName() -> String { - return self.valueForProperty(kABFirstNameProperty) as String? ?? "" + return self.valueForProperty(kABFirstNameProperty) as! String? ?? "" } func lastName() -> String { - return self.valueForProperty(kABLastNameProperty) as String? ?? "" + return self.valueForProperty(kABLastNameProperty) as! String? ?? "" } func emails() -> ABMultiValue? { - return self.valueForProperty(kABEmailProperty) as ABMultiValue? + return self.valueForProperty(kABEmailProperty) as! ABMultiValue? } func setImageDataFromURL(optionalURL: NSURL?) { diff --git a/Contacts/String.swift b/Contacts/String.swift index 9267c31..1f90d34 100644 --- a/Contacts/String.swift +++ b/Contacts/String.swift @@ -24,6 +24,6 @@ extension String { result.destroy() - return String(format: hash) + return String(format: hash as String) } } \ No newline at end of file diff --git a/Contacts/main.swift b/Contacts/main.swift index 46c9c8e..3acf27e 100644 --- a/Contacts/main.swift +++ b/Contacts/main.swift @@ -10,7 +10,7 @@ import Foundation import AddressBook let addressbook = ABAddressBook() -let people = addressbook.people() as [ABPerson] +let people = addressbook.people() as! [ABPerson] for person in people { if let emails = person.emails() { diff --git a/Gravatar2Contacts.xcodeproj/project.pbxproj b/Gravatar2Contacts.xcodeproj/project.pbxproj index 00a9c57..f8229b4 100644 --- a/Gravatar2Contacts.xcodeproj/project.pbxproj +++ b/Gravatar2Contacts.xcodeproj/project.pbxproj @@ -115,6 +115,8 @@ 5C2C4E6A19FC86310049C01A /* Project object */ = { isa = PBXProject; attributes = { + LastSwiftMigration = 0710; + LastSwiftUpdateCheck = 0710; LastUpgradeCheck = 0610; ORGANIZATIONNAME = "Chad Pytel"; TargetAttributes = { From 04ed6de7415cea43b291fb8a15fc29bf69a7bf61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Payche=CC=80re?= Date: Tue, 17 Nov 2015 11:48:59 +0100 Subject: [PATCH 2/4] Fixed build for Xcode 7.1.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Paychère --- Contacts/String.swift | 2 +- Contacts/main.swift | 4 ++-- Gravatar2Contacts.xcodeproj/project.pbxproj | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Contacts/String.swift b/Contacts/String.swift index 1f90d34..88a6a77 100644 --- a/Contacts/String.swift +++ b/Contacts/String.swift @@ -17,7 +17,7 @@ extension String { CC_MD5(str!, strLen, result) - var hash = NSMutableString() + let hash = NSMutableString() for i in 0.. Date: Tue, 17 Nov 2015 15:38:33 +0100 Subject: [PATCH 3/4] Improved update mechanism MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Only search for gravatar of entries without image (avoid overriding custom set images) - Only apply images for valid gravatars - handle async execution of URL requests Signed-off-by: Stefan Paychère --- Contacts/ABPerson.swift | 8 -------- Contacts/main.swift | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Contacts/ABPerson.swift b/Contacts/ABPerson.swift index b044fb3..3309012 100644 --- a/Contacts/ABPerson.swift +++ b/Contacts/ABPerson.swift @@ -22,12 +22,4 @@ extension ABPerson { return self.valueForProperty(kABEmailProperty) as! ABMultiValue? } - func setImageDataFromURL(optionalURL: NSURL?) { - if let url = optionalURL { - let data = NSData(contentsOfURL: url) - if data != nil { - self.setImageData(data) - } - } - } } \ No newline at end of file diff --git a/Contacts/main.swift b/Contacts/main.swift index 14aa181..b8cc5e1 100644 --- a/Contacts/main.swift +++ b/Contacts/main.swift @@ -11,15 +11,43 @@ import AddressBook let addressbook = ABAddressBook() let people = addressbook.people() as! [ABPerson] +let group = dispatch_group_create() +let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) for person in people { - if let emails = person.emails() { - print("Finding Gravatar for \(person.firstName()) \(person.lastName())...") - - for i in 0.. Date: Tue, 17 Nov 2015 15:42:38 +0100 Subject: [PATCH 4/4] Updated readme with new behaviour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Paychère --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index 63fa2d0..efbf2af 100644 --- a/README.md +++ b/README.md @@ -10,15 +10,9 @@ the email address for the contact. To run it, open the project in XCode and Run. +The program will only query Gravatars for contacts without image. As a result, already set images (manual or previous runs) will be kept. If no Gravatar is found for a contact it does not change the image. -However, if any Gravatar is found for a contact, it will replace the existing -image. In other words, we always use the latest image from Gravatar. - -This has the side effect that if you change an image for a contact, run this -program, and they have a different Gravatar, your custom image will be -overwritten. - ### Known Issues * If a contact has multiple email address with Gravatars associated with them,