12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- //
- // NSMutableString+AvoidCrash.m
- // https://github.com/chenfanfang/AvoidCrash
- //
- // Created by mac on 16/10/6.
- // Copyright © 2016年 chenfanfang. All rights reserved.
- //
- #import "NSMutableString+AvoidCrash.h"
- #import "AvoidCrash.h"
- @implementation NSMutableString (AvoidCrash)
- + (void)avoidCrashExchangeMethod {
-
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
-
- Class stringClass = NSClassFromString(@"__NSCFString");
-
- //replaceCharactersInRange
- [AvoidCrash exchangeInstanceMethod:stringClass method1Sel:@selector(replaceCharactersInRange:withString:) method2Sel:@selector(avoidCrashReplaceCharactersInRange:withString:)];
-
- //insertString:atIndex:
- [AvoidCrash exchangeInstanceMethod:stringClass method1Sel:@selector(insertString:atIndex:) method2Sel:@selector(avoidCrashInsertString:atIndex:)];
-
- //deleteCharactersInRange
- [AvoidCrash exchangeInstanceMethod:stringClass method1Sel:@selector(deleteCharactersInRange:) method2Sel:@selector(avoidCrashDeleteCharactersInRange:)];
- });
- }
- //=================================================================
- // replaceCharactersInRange
- //=================================================================
- #pragma mark - replaceCharactersInRange
- - (void)avoidCrashReplaceCharactersInRange:(NSRange)range withString:(NSString *)aString {
-
- @try {
- [self avoidCrashReplaceCharactersInRange:range withString:aString];
- }
- @catch (NSException *exception) {
- NSString *defaultToDo = AvoidCrashDefaultIgnore;
- [AvoidCrash noteErrorWithException:exception defaultToDo:defaultToDo];
- }
- @finally {
-
- }
- }
- //=================================================================
- // insertString:atIndex:
- //=================================================================
- #pragma mark - insertString:atIndex:
- - (void)avoidCrashInsertString:(NSString *)aString atIndex:(NSUInteger)loc {
-
- @try {
- [self avoidCrashInsertString:aString atIndex:loc];
- }
- @catch (NSException *exception) {
- NSString *defaultToDo = AvoidCrashDefaultIgnore;
- [AvoidCrash noteErrorWithException:exception defaultToDo:defaultToDo];
- }
- @finally {
-
- }
- }
- //=================================================================
- // deleteCharactersInRange
- //=================================================================
- #pragma mark - deleteCharactersInRange
- - (void)avoidCrashDeleteCharactersInRange:(NSRange)range {
-
- @try {
- [self avoidCrashDeleteCharactersInRange:range];
- }
- @catch (NSException *exception) {
- NSString *defaultToDo = AvoidCrashDefaultIgnore;
- [AvoidCrash noteErrorWithException:exception defaultToDo:defaultToDo];
- }
- @finally {
-
- }
- }
- @end
|