Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.proArray = [[NSMutableArray alloc]init];
GCDVC2* __weak weakSelf = self;
self.postGCDBlock = ^{
[weakSelf.proArray removeObject:@"3"];
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.proArray = [[NSMutableArray alloc]init];
GCDVC2* __weak weakSelf = self;
self.postGCDBlock = ^{
[weakSelf.proArray removeObject:@"3"];
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.proArray = [[NSMutableArray alloc]init];
GCDVC2* __weak weakSelf = self;
self.postGCDBlock = ^{
GCDVC2* __strong strongSelf = weakSelf;
- (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation *)invocation completionHandler:(void (^)(NSError * _Nullable nilOrError))completionHandler {
//Checks if the file contains source code of Objective-C or Swift. Then is sets the appropriate variables
if ([invocation.buffer.contentUTI isEqualToString:@"public.objective-c-source"]) {
logString = @"NSLog(";
logCommentString=@"DSLog(";
regularExpressionString =@"NSLog\\([^\\)]*\\)[\\s]*\\;";
regularExpressionCommentString=@"\\/\\*DSLog\\([^\\)]*\\)[\\s]*\\;\\*\\/";
}
else if ([invocation.buffer.contentUTI isEqualToString:@"public.swift-source"]){
#import "NSUserDefaults+MyUserDefaults.h"
@implementation NSUserDefaults (MyUserDefaults)
-(void)mySetObject:(id)value forKey:(NSString *)defaultName {
[self setObject:value forKey:defaultName];
NSLog(@"Set object %@ for key %@",value,defaultName);
}
@end
#import "ViewController.h"
#import "NSUserDefaults+MyUserDefaults.h"
@interface ViewController ()
@end
@implementation ViewController
#import "NSUserDefaults+MonitoringWrites.h"
#import <objc/runtime.h>
@implementation NSUserDefaults (MonitoringWrites)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL defaultSelector = @selector(setObject:forKey:);
SEL swizzledSelector = @selector(swizzled_setObject:forKey:);
Method defaultMethod = class_getInstanceMethod([self class], defaultSelector);
Method swizzledMethod = class_getInstanceMethod([self class], swizzledSelector);
BOOL isMethodExists = !class_addMethod([self class], defaultSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
BOOL isMethodExists = !class_addMethod([self class], defaultSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
if (isMethodExists) {
method_exchangeImplementations(defaultMethod, swizzledMethod);
}
else {
class_replaceMethod([self class], swizzledSelector, method_getImplementation(defaultMethod), method_getTypeEncoding(defaultMethod));
}
- (void)swizzled_setObject:(id)value forKey:(NSString *)defaultName {
[self swizzled_setObject:value forKey:defaultName];
NSLog(@"Set Object %@ for key %@",value,defaultName);
}