You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should the hack part been moved to the UIImageView+BetterFace.m ? #12
I use this code and success to parse the image in the demo.
I think it would be more intuitive and save the work to deal with "main.m".
Or is there a specific reason not to?
@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
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:
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~
Activity
croath commentedon Apr 2, 2015
@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:
hack_uiimageview_bf();method into itsload, developer may have no chance to turn off the feature for example of being in debugging mode.+loadmethod in the class's categoryextension 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.
WenchaoD commentedon Apr 7, 2015
setBetterFaceImageout there, that could be aswitchinstead. When users need that feature, they callsetBetterfaceImage, when they don't, they could just callsetImage. As a result, thehack thingis no longer needed, thesetBetterfaceImagecould be like this:I hope this could make sense.
+initializeas 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 anycompatibilitywork. Maybe the only limitation is that the class must be a NSObject subclass~croath commentedon Aug 26, 2016
Could you please check out #13 , especially the readme file diff?