GithubHelp home page GithubHelp logo

Comments (3)

croath avatar croath commented on August 29, 2024

@f33chobits Thank you for your issue, and sorry for the late reply.

Yes there is a specific reason, like developer may not need this feature in some situation. For details:

  • If you put the hack_uiimageview_bf(); method into its load, developer may have no chance to turn off the feature for example of being in debugging mode.
  • I think it's better to run all method swizzling code at the very beginning.
  • I don't know if it's ok to override a +load method in the class's category
  • If you'd like to do it, you could checkout https://github.com/croath/UIImageView-BetterFace-Swift do something like this in Swift:
extension UIImageView {
    public override class func initialize() {
        struct Static {
            static var token: dispatch_once_t = 0
        }

        dispatch_once(&Static.token) {
// your swizzle code
        }
    }

I hope my answer could make some sense.

from uiimageview-betterface.

WenchaoD avatar WenchaoD commented on August 29, 2024
  • I understand you add hack_uiimageview_bf() as a switch to control whether users use this feature. But this is not a single switch, it's a global switch. When it's turned on, all UIImage instances will have that feature. As you have left an interface setBetterFaceImage out there, that could be a switch instead. When users need that feature, they call setBetterfaceImage, when they don't, they could just call setImage. As a result, the hack thing is no longer needed, the setBetterfaceImage could be like this:
- (void)setBetterFaceImage:(UIImage *)image{
    [self setImage:image]; // instead of swizzling [self setBetterFaceImage:image]
    if (![self needsBetterFace]) {
        return;
    }
    [self faceDetect:image];
}

I hope this could make sense.

  • In objective-c it is ok to override a +load method in the class's category and do swizzling in it. But I used to do swizzling in swift +initialize as you mentioned and met some problem which could make app crash. I don't know whether it could work now, but it couldn't months ago. What I'm doing is just create objective-c class and do swizzling in +(void)load in Swift Project and it works fine, no need to import in bridge header, also no need to do any compatibility work. Maybe the only limitation is that the class must be a NSObject subclass~

from uiimageview-betterface.

croath avatar croath commented on August 29, 2024

Could you please check out #13 , especially the readme file diff?

from uiimageview-betterface.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.