标签:空值 send str sources htm lan uil tcl sof
// // NSURL+url.h // iOS_study00 // // Created by Datacvg on 2019/9/6. // Copyright © 2019 Datacvg. All rights reserved. // #import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN @interface NSURL (url) +(instancetype)SL_URLWithString:(NSString*)URLString; @end NS_ASSUME_NONNULL_END
// // NSURL+url.m // iOS_study00 // // Created by Datacvg on 2019/9/6. // Copyright © 2019 Datacvg. All rights reserved. // #import "NSURL+url.h" #import <objc/runtime.h> @implementation NSURL (url) +(void)load { /** 在类加载方法里面使用RunTime实现方法交换(URLWithString与SL_URLWithString) load加载比init alloc都早 没有使用NSURL类也会加载(程序运行就会加载) NSURL+url.m在Build Phases -> Compile Sources 里面原文件参与编译 */ //class_getInstanceMethod :获取对象方法 //class_getClassMethod: 获取类方法 Method URLWithString = class_getClassMethod([NSURL class], @selector(URLWithString:)); Method SLURLWithString = class_getClassMethod([NSURL class], @selector(SL_URLWithString:)); //交换 method_exchangeImplementations(URLWithString, SLURLWithString); } +(instancetype)SL_URLWithString:(NSString *)URLString { //方法交换后SL_URLWithStringy对应系统方法URLWithString NSURL * url = [NSURL SL_URLWithString:URLString]; if (url == nil) { NSLog(@"url为空"); } return url; } @end
标签:空值 send str sources htm lan uil tcl sof
原文地址:https://www.cnblogs.com/lulushen/p/11473809.html