1

I'm following the tutorial here to display GIF image on UIImage. I have write the extension UIImage+GIF.swift which basically like this:

extension UIImage {

    public class func gifImage(named: String) -> UIImage {
        ...
    }
}

along with bunch other functions.

But when I tried to do this:

myImageView.image = UIImage.gifImage(named: "loading.gif");

Xcode complains type UIImage has no member "gifImage". Why? Any how can I fix this? Thanks.

EDIT:

I have also tried to make it a static function like this, but it still doesn't work:

extension UIImage {

    static func gifImage(named: String) -> UIImage {
        ...
    }
}
Chen Li Yong
  • 5,459
  • 8
  • 58
  • 124
  • [http://stackoverflow.com/questions/27919620/how-to-load-gif-image-in-swift](http://stackoverflow.com/questions/27919620/how-to-load-gif-image-in-swift) – Nirav Hathi Apr 13 '17 at 06:21
  • @NiravHathi thanks. I actually found the link in my question through this same QA. which led to the original issue here where I can't access static functions on this particular extension. – Chen Li Yong Apr 13 '17 at 06:26

2 Answers2

0
import UIKit    
extension UIImage {
        func gifImage(named: String) -> UIImage {
            //Add your logic here
        }
    }

This should work.

  • How if I want to add a "static" function? Function which I can call from `UIImage` class directly without instantiating it. – Chen Li Yong Apr 13 '17 at 06:00
0

Make your extenssion public

public extension UIImage {

public func gifImage(named: String) -> UIImage {
    ...
}
}

use extenssion like this

yourImageView.gifImage(named: "your image name") 
Uma_Shanker_Tiwari
  • 453
  • 1
  • 3
  • 16