Files
comaps/iphone/Maps/Core/Theme/Swizzle/SwizzleStyle.m
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

34 lines
1.2 KiB
Objective-C

#import "SwizzleStyle.h"
#import <UIKit/UIKit.h>
#import "objc/runtime.h"
#import "objc/message.h"
@implementation SwizzleStyle
+ (void)swizzle
{
[SwizzleStyle swizzle:[UISearchBar class] methodName:@"didMoveToWindow"];
[SwizzleStyle swizzle:[UITextField class] methodName:@"didMoveToWindow"];
[SwizzleStyle swizzle:[UIView class] methodName:@"didMoveToWindow"];
}
+ (void)swizzle:(Class)forClass methodName:(NSString*)methodName
{
SEL originalMethod = NSSelectorFromString(methodName);
SEL newMethod = NSSelectorFromString([NSString stringWithFormat:@"%@%@", @"sw_", methodName]);
[SwizzleStyle swizzle:forClass from:originalMethod to:newMethod];
}
+ (void)swizzle:(Class)forClass from:(SEL)original to:(SEL)new
{
Method originalMethod = class_getInstanceMethod(forClass, original);
Method newMethod = class_getInstanceMethod(forClass, new);
if (class_addMethod(forClass, original, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) {
class_replaceMethod(forClass, new, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, newMethod);
}
}
@end