SwiftGif icon indicating copy to clipboard operation
SwiftGif copied to clipboard

Fail to Load GIF in new xcode 10 update with ios 12

Open SubhadipDutta93 opened this issue 7 years ago • 4 comments

Once i run my app in the debug terminal it shows this - "SwiftGif: Cannot turn image named "battery" into NSDataAsset" how to solve this problem? Thanks in advance.

SubhadipDutta93 avatar Sep 22 '18 14:09 SubhadipDutta93

Don't use XCAsset

ArtFeel avatar Oct 01 '18 16:10 ArtFeel

heap buffer overflow ... library crashed

imdinesh58 avatar Nov 17 '18 08:11 imdinesh58

@SubhadipDutta93 and others what I did is:

  • create a new group called Gifs (you can name it whatever you want)
  • put your files in there

imageView.image = UIImage.gif(name: gifName)

public class func gif(name: String) -> UIImage? {
        guard let bundleURL = Bundle.main
            .url(forResource: name, withExtension: "gif") else {
                print("SwiftGif: This image named \"\(name)\" does not exist")
                return nil
        }
        guard let imageData = try? Data(contentsOf: bundleURL) else {
            print("SwiftGif: Cannot turn image named \"\(name)\" into NSData")
            return nil
        }
        
        return gif(data: imageData)
    }

works like a charm

bartoslaw avatar Dec 20 '18 13:12 bartoslaw

+1 for this - didn't work in the Assets folder, worked find elsewhere

SteveBlackUK avatar Oct 12 '20 20:10 SteveBlackUK