Skip to content

Instantly share code, notes, and snippets.

@touyou
Created April 12, 2016 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save touyou/878044febdb8eeda0f5d0db967f7e059 to your computer and use it in GitHub Desktop.
Save touyou/878044febdb8eeda0f5d0db967f7e059 to your computer and use it in GitHub Desktop.
NSDataがGIFかどうか判断するためのExtensionのSwift版。Objc-Cで書かれた https://gist.github.com/cathandnya/7279009 を参考にしました。
extension NSData {
func isGIF() -> Bool {
let bytes = UnsafePointer<Int8>(self.bytes)
return self.length >= 6 && (strncmp(bytes, "GIF87a", 6) == 0 || strncmp(bytes, "GIF89a", 6) == 0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment