From 3a0f19cdee6b782da73e86b71235caeb7ad2ed46 Mon Sep 17 00:00:00 2001 From: Goktug Yilmaz Date: Mon, 12 Oct 2015 21:09:51 +0300 Subject: [PATCH 01/10] Added swift2 update check message tracker --- SwiftGif.xcodeproj/project.pbxproj | 1 + 1 file changed, 1 insertion(+) diff --git a/SwiftGif.xcodeproj/project.pbxproj b/SwiftGif.xcodeproj/project.pbxproj index a1059ef..3a9eb4b 100644 --- a/SwiftGif.xcodeproj/project.pbxproj +++ b/SwiftGif.xcodeproj/project.pbxproj @@ -155,6 +155,7 @@ 14A76430194EFBB800A74B1F /* Project object */ = { isa = PBXProject; attributes = { + LastSwiftUpdateCheck = 0700; LastUpgradeCheck = 0600; ORGANIZATIONNAME = "Arne Bahlo"; TargetAttributes = { From aa94144ff78126a900dac2d8b0bd30e30768eca2 Mon Sep 17 00:00:00 2001 From: Arne Bahlo Date: Mon, 12 Oct 2015 21:02:59 +0200 Subject: [PATCH 02/10] Update .travis.yml - Add locale, print env. --- .travis.yml | 8 +++++++- .../xcschemes/SwiftGif.xcscheme | 17 +++++++++++------ .../xcschemes/xcschememanagement.plist | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) rename SwiftGif.xcodeproj/{xcuserdata/arne.xcuserdatad => xcshareddata}/xcschemes/SwiftGif.xcscheme (91%) diff --git a/.travis.yml b/.travis.yml index 49b7066..fffd125 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,8 @@ -language: swift +language: objective-c +osx_image: xcode7 +script: + - xctool + -project SwiftGif.xcodeproj -scheme SwiftGif + -sdk iphonesimulator build test + CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY="" diff --git a/SwiftGif.xcodeproj/xcuserdata/arne.xcuserdatad/xcschemes/SwiftGif.xcscheme b/SwiftGif.xcodeproj/xcshareddata/xcschemes/SwiftGif.xcscheme similarity index 91% rename from SwiftGif.xcodeproj/xcuserdata/arne.xcuserdatad/xcschemes/SwiftGif.xcscheme rename to SwiftGif.xcodeproj/xcshareddata/xcschemes/SwiftGif.xcscheme index d58a5ea..0b0cb33 100644 --- a/SwiftGif.xcodeproj/xcuserdata/arne.xcuserdatad/xcschemes/SwiftGif.xcscheme +++ b/SwiftGif.xcodeproj/xcshareddata/xcschemes/SwiftGif.xcscheme @@ -23,10 +23,10 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -48,17 +48,21 @@ ReferencedContainer = "container:SwiftGif.xcodeproj"> + + - + - + SchemeUserState - SwiftGif.xcscheme + SwiftGif.xcscheme_^#shared#^_ orderHint 0 From 77cd9a6ea695eeeeca640fe87b33e4faffb40534 Mon Sep 17 00:00:00 2001 From: Arne Bahlo Date: Mon, 12 Oct 2015 21:44:31 +0200 Subject: [PATCH 03/10] Add build status badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 956edf6..c8d473c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# SwiftGif +# SwiftGif [![Build Status](https://travis-ci.org/bahlo/SwiftGif.svg?branch=master)](https://travis-ci.org/bahlo/SwiftGif) A small `UIImage` extension with gif support. From b63021209a20857ebd82043a9e45a9d22ab3f738 Mon Sep 17 00:00:00 2001 From: Goktug Yilmaz Date: Mon, 12 Oct 2015 21:34:39 +0300 Subject: [PATCH 04/10] Update UIImage+Gif.swift --- SwiftGifCommon/UIImage+Gif.swift | 78 ++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/SwiftGifCommon/UIImage+Gif.swift b/SwiftGifCommon/UIImage+Gif.swift index 1f6f078..88aba53 100755 --- a/SwiftGifCommon/UIImage+Gif.swift +++ b/SwiftGifCommon/UIImage+Gif.swift @@ -10,17 +10,30 @@ import UIKit import ImageIO extension UIImage { - - public class func animatedImageWithData(data: NSData) -> UIImage? { - guard let source = CGImageSourceCreateWithData(data, nil) else { return nil } - + + class func gifWithData(data: NSData) -> UIImage? { + guard let source = CGImageSourceCreateWithData(data, nil) else { + print("SwiftGif: Source for the image does not exist") + return nil + } return UIImage.animatedImageWithSource(source) } - - class func delayForImageAtIndex(index: Int, source: CGImageSource!) - -> Double { + + class func gifWithName(name: String) -> UIImage? { + guard let bundleURL = NSBundle.mainBundle().URLForResource(name, withExtension: "gif") else { + print("SwiftGif: This image named \"\(name)\" does not exist") + return nil + } + guard let imageData = NSData(contentsOfURL: bundleURL) else { + print("SwiftGif: Cannot turn image named \"\(name)\" into NSData") + return nil + } + return gifWithData(imageData) + } + + class func delayForImageAtIndex(index: Int, source: CGImageSource!) -> Double { var delay = 0.1 - + // Get dictionaries let cfProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil) let gifProperties: CFDictionaryRef = unsafeBitCast( @@ -37,17 +50,16 @@ extension UIImage { delayObject = unsafeBitCast(CFDictionaryGetValue(gifProperties, unsafeAddressOf(kCGImagePropertyGIFDelayTime)), AnyObject.self) } - + delay = delayObject as! Double - + if delay < 0.1 { delay = 0.1 // Make sure they're not too fast } - - + return delay } - + class func gcdForPair(var a: Int?, var _ b: Int?) -> Int { // Check if one of them is nil if b == nil || a == nil { @@ -59,19 +71,19 @@ extension UIImage { return 0 } } - + // Swap for modulo if a < b { let c = a a = b b = c } - + // Get greatest common divisor var rest: Int while true { rest = a! % b! - + if rest == 0 { return b! // Found it } else { @@ -80,70 +92,70 @@ extension UIImage { } } } - + class func gcdForArray(array: Array) -> Int { if array.isEmpty { return 1 } - + var gcd = array[0] - + for val in array { gcd = UIImage.gcdForPair(val, gcd) } - + return gcd } - - public class func animatedImageWithSource(source: CGImageSource) -> UIImage? { + + class func animatedImageWithSource(source: CGImageSource) -> UIImage? { let count = CGImageSourceGetCount(source) var images = [CGImageRef]() var delays = [Int]() - + // Fill arrays for i in 0.. Date: Mon, 12 Oct 2015 21:37:29 +0300 Subject: [PATCH 05/10] Update RootViewController.swift --- SwiftGifDemo/RootViewController.swift | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/SwiftGifDemo/RootViewController.swift b/SwiftGifDemo/RootViewController.swift index 0e21fb7..82f596b 100644 --- a/SwiftGifDemo/RootViewController.swift +++ b/SwiftGifDemo/RootViewController.swift @@ -22,22 +22,19 @@ class RootViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - var imageData = NSData(contentsOfURL: NSBundle.mainBundle() - .URLForResource("jeremy", withExtension: "gif")!) - let jeremy = UIImage.animatedImageWithData(imageData!) - var imageView = UIImageView(image: jeremy) + let jeremyGif = UIImage.gifWithName("jeremy") + let imageView = UIImageView(image: jeremyGif) imageView.frame = CGRect(x: 0.0, y: 20.0, width: 350.0, height: 202.0) view.addSubview(imageView) - imageData = NSData(contentsOfURL: NSBundle.mainBundle() - .URLForResource("adventure-time", withExtension: "gif")!) - let advTime = UIImage.animatedImageWithData(imageData!) - imageView = UIImageView(image: advTime) - imageView.frame = CGRect(x: 0.0, y: 222.0, width: 350.0, height: 202.0) + let imageData = NSData(contentsOfURL: NSBundle.mainBundle().URLForResource("adventure-time", withExtension: "gif")!) + let advTimeGif = UIImage.gifWithData(imageData!) + let imageView2 = UIImageView(image: advTimeGif) + imageView2.frame = CGRect(x: 0.0, y: 222.0, width: 350.0, height: 202.0) - view.addSubview(imageView) + view.addSubview(imageView2) } override func didReceiveMemoryWarning() { From ba6828cd5efb8cd32cb8f97cfdab4f42b595d370 Mon Sep 17 00:00:00 2001 From: Goktug Yilmaz Date: Mon, 12 Oct 2015 21:39:22 +0300 Subject: [PATCH 06/10] Update README.md --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c8d473c..797a526 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,10 @@ A small `UIImage` extension with gif support. Import the `Gif.swift` in your project and do the following: ```swift // jeremy.gif -var url = NSBundle.mainBundle().URLForResource("jeremy", withExtension: "gif") -var imageData = NSData(contentsOfURL: url) - // Returns an animated UIImage -UIImage.animatedImageWithData(imageData) +let jeremyGif = UIImage.gifWithName("jeremy") +// Use the UIImage in your UIImageView +let imageView = UIImageView(image: jeremyGif) ``` ## How does it work? From 8a3502e3c2afb729fa636ebb05f579638ad46c7d Mon Sep 17 00:00:00 2001 From: Goktug Yilmaz Date: Tue, 13 Oct 2015 12:27:55 +0300 Subject: [PATCH 07/10] added public statements --- SwiftGifCommon/UIImage+Gif.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftGifCommon/UIImage+Gif.swift b/SwiftGifCommon/UIImage+Gif.swift index 88aba53..b217ba5 100755 --- a/SwiftGifCommon/UIImage+Gif.swift +++ b/SwiftGifCommon/UIImage+Gif.swift @@ -11,7 +11,7 @@ import ImageIO extension UIImage { - class func gifWithData(data: NSData) -> UIImage? { + public class func gifWithData(data: NSData) -> UIImage? { guard let source = CGImageSourceCreateWithData(data, nil) else { print("SwiftGif: Source for the image does not exist") return nil @@ -19,7 +19,7 @@ extension UIImage { return UIImage.animatedImageWithSource(source) } - class func gifWithName(name: String) -> UIImage? { + public class func gifWithName(name: String) -> UIImage? { guard let bundleURL = NSBundle.mainBundle().URLForResource(name, withExtension: "gif") else { print("SwiftGif: This image named \"\(name)\" does not exist") return nil From e52c3436b02c59bff5b225500254985c785c1f53 Mon Sep 17 00:00:00 2001 From: Arne Bahlo Date: Tue, 13 Oct 2015 14:03:22 +0200 Subject: [PATCH 08/10] Better markup in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 797a526..d735233 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ A small `UIImage` extension with gif support. ## Usage Import the `Gif.swift` in your project and do the following: ```swift -// jeremy.gif // Returns an animated UIImage let jeremyGif = UIImage.gifWithName("jeremy") + // Use the UIImage in your UIImageView let imageView = UIImageView(image: jeremyGif) ``` From ebb9c66b88dd7f395126e42eb2a4c1a5aaa6a847 Mon Sep 17 00:00:00 2001 From: Arne Bahlo Date: Tue, 13 Oct 2015 14:07:10 +0200 Subject: [PATCH 09/10] Add badges For carthage, cocoapods, license and swift version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d735233..d41f46a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# SwiftGif [![Build Status](https://travis-ci.org/bahlo/SwiftGif.svg?branch=master)](https://travis-ci.org/bahlo/SwiftGif) +# SwiftGif [![Swift 2.0](https://img.shields.io/badge/Swift-2.0-orange.svg?style=flat)](https://developer.apple.com/swift/) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![CocoaPods](https://img.shields.io/cocoapods/v/SwiftGifOrigin.svg)](http://cocoadocs.org/docsets/SwiftGifOrigin) [![License MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](https://github.com/Carthage/Carthage) [![Build Status](https://travis-ci.org/bahlo/SwiftGif.svg?branch=master)](https://travis-ci.org/bahlo/SwiftGif) A small `UIImage` extension with gif support. From f5e936cd97dfea33db7516c63eb84df01cdfc90e Mon Sep 17 00:00:00 2001 From: Arne Bahlo Date: Tue, 13 Oct 2015 14:23:46 +0200 Subject: [PATCH 10/10] Update to recommended settings --- SwiftGif.xcodeproj/project.pbxproj | 7 ++++++- .../xcshareddata/xcschemes/SwiftGif.xcscheme | 2 +- SwiftGifDemo/Info.plist | 2 +- SwiftGifTests/Info.plist | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/SwiftGif.xcodeproj/project.pbxproj b/SwiftGif.xcodeproj/project.pbxproj index 3a9eb4b..ff88991 100644 --- a/SwiftGif.xcodeproj/project.pbxproj +++ b/SwiftGif.xcodeproj/project.pbxproj @@ -156,7 +156,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0600; + LastUpgradeCheck = 0700; ORGANIZATIONNAME = "Arne Bahlo"; TargetAttributes = { 14A76437194EFBB800A74B1F = { @@ -258,6 +258,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -322,6 +323,7 @@ ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; INFOPLIST_FILE = "$(SRCROOT)/SwiftGifDemo/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "me.arne.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -333,6 +335,7 @@ ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; INFOPLIST_FILE = "$(SRCROOT)/SwiftGifDemo/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "me.arne.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -352,6 +355,7 @@ INFOPLIST_FILE = SwiftGifTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = YES; + PRODUCT_BUNDLE_IDENTIFIER = "me.arne.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; }; @@ -368,6 +372,7 @@ INFOPLIST_FILE = SwiftGifTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = "me.arne.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; }; diff --git a/SwiftGif.xcodeproj/xcshareddata/xcschemes/SwiftGif.xcscheme b/SwiftGif.xcodeproj/xcshareddata/xcschemes/SwiftGif.xcscheme index 0b0cb33..db5b63b 100644 --- a/SwiftGif.xcodeproj/xcshareddata/xcschemes/SwiftGif.xcscheme +++ b/SwiftGif.xcodeproj/xcshareddata/xcschemes/SwiftGif.xcscheme @@ -1,6 +1,6 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - me.arne.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/SwiftGifTests/Info.plist b/SwiftGifTests/Info.plist index 2d1f328..6d32c15 100644 --- a/SwiftGifTests/Info.plist +++ b/SwiftGifTests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - me.arne.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName