diff --git a/SafeObject.podspec b/SafeObject.podspec index a6c242a..0788bda 100644 --- a/SafeObject.podspec +++ b/SafeObject.podspec @@ -1,14 +1,14 @@ Pod::Spec.new do |s| -s.name = 'SafeObject' -s.version = '0.0.1' -s.authors = { 'daniulaolu' => '287929070@qq.com' } -s.homepage = 'https://github.com/MrLujh/SafeObject' +s.name = 'SafeObject_zp' +s.version = '0.1.1' +s.authors = { 'ZPP506' => '94460330@qq.com' } +s.homepage = 'https://github.com/ZPP506/SafeObject' s.summary = '项目中防止数组字典崩溃' -s.source = { :git => 'https://github.com/MrLujh/SafeObject.git', +s.source = { :git => 'https://github.com/ZPP506/SafeObject.git', :tag => s.version.to_s } s.license = { :type => "MIT", :file => "LICENSE" } s.platform = :ios, '7.0' s.requires_arc = true -s.source_files = "SafeObject", "*.{h,m}" +s.source_files = "SafeObject_zp", "*.{h,m}" s.ios.deployment_target = '7.0' end \ No newline at end of file diff --git a/SafeObjectCrash.xcodeproj/project.pbxproj b/SafeObjectCrash.xcodeproj/project.pbxproj index c9f70d7..b4975b1 100644 --- a/SafeObjectCrash.xcodeproj/project.pbxproj +++ b/SafeObjectCrash.xcodeproj/project.pbxproj @@ -20,6 +20,8 @@ 2E14AA3D208722DD009878C7 /* NSObject+Swizzling.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E14AA36208722DC009878C7 /* NSObject+Swizzling.m */; }; 2E14AA3E208722DD009878C7 /* NSArray+Safe.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E14AA37208722DC009878C7 /* NSArray+Safe.m */; }; 2E14AA3F208722DD009878C7 /* NSObject+ImpChangeTool.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E14AA38208722DC009878C7 /* NSObject+ImpChangeTool.m */; }; + 848FED29225DE3C700938C39 /* NSAttributedString+zp_Safe.m in Sources */ = {isa = PBXBuildFile; fileRef = 848FED28225DE3C700938C39 /* NSAttributedString+zp_Safe.m */; }; + 848FED2C225DE3E100938C39 /* NSMutableAttributedString+zp_Safe.m in Sources */ = {isa = PBXBuildFile; fileRef = 848FED2B225DE3E100938C39 /* NSMutableAttributedString+zp_Safe.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -48,6 +50,10 @@ 2E14AA36208722DC009878C7 /* NSObject+Swizzling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+Swizzling.m"; sourceTree = ""; }; 2E14AA37208722DC009878C7 /* NSArray+Safe.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+Safe.m"; sourceTree = ""; }; 2E14AA38208722DC009878C7 /* NSObject+ImpChangeTool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+ImpChangeTool.m"; sourceTree = ""; }; + 848FED27225DE3C700938C39 /* NSAttributedString+zp_Safe.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSAttributedString+zp_Safe.h"; sourceTree = ""; }; + 848FED28225DE3C700938C39 /* NSAttributedString+zp_Safe.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSAttributedString+zp_Safe.m"; sourceTree = ""; }; + 848FED2A225DE3E100938C39 /* NSMutableAttributedString+zp_Safe.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSMutableAttributedString+zp_Safe.h"; sourceTree = ""; }; + 848FED2B225DE3E100938C39 /* NSMutableAttributedString+zp_Safe.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSMutableAttributedString+zp_Safe.m"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -112,6 +118,10 @@ 2E14AA38208722DC009878C7 /* NSObject+ImpChangeTool.m */, 2E14AA31208722DC009878C7 /* NSObject+Swizzling.h */, 2E14AA36208722DC009878C7 /* NSObject+Swizzling.m */, + 848FED27225DE3C700938C39 /* NSAttributedString+zp_Safe.h */, + 848FED28225DE3C700938C39 /* NSAttributedString+zp_Safe.m */, + 848FED2A225DE3E100938C39 /* NSMutableAttributedString+zp_Safe.h */, + 848FED2B225DE3E100938C39 /* NSMutableAttributedString+zp_Safe.m */, ); path = SafeObject; sourceTree = SOURCE_ROOT; @@ -187,7 +197,9 @@ buildActionMask = 2147483647; files = ( 2E14AA39208722DD009878C7 /* NSMutableArray+Safe.m in Sources */, + 848FED29225DE3C700938C39 /* NSAttributedString+zp_Safe.m in Sources */, 2E14A9CD208717BF009878C7 /* ViewController.m in Sources */, + 848FED2C225DE3E100938C39 /* NSMutableAttributedString+zp_Safe.m in Sources */, 2E14AA3E208722DD009878C7 /* NSArray+Safe.m in Sources */, 2E14A9D8208717C0009878C7 /* main.m in Sources */, 2E14AA3F208722DD009878C7 /* NSObject+ImpChangeTool.m in Sources */, @@ -336,7 +348,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 9M422A22FH; + DEVELOPMENT_TEAM = 423Z88A982; INFOPLIST_FILE = SafeObjectCrash/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -353,7 +365,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 9M422A22FH; + DEVELOPMENT_TEAM = 423Z88A982; INFOPLIST_FILE = SafeObjectCrash/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", diff --git a/SafeObject/NSArray+Safe.h b/SafeObject_zp/NSArray+Safe.h similarity index 100% rename from SafeObject/NSArray+Safe.h rename to SafeObject_zp/NSArray+Safe.h diff --git a/SafeObject/NSArray+Safe.m b/SafeObject_zp/NSArray+Safe.m similarity index 100% rename from SafeObject/NSArray+Safe.m rename to SafeObject_zp/NSArray+Safe.m diff --git a/SafeObject_zp/NSAttributedString+zp_Safe.h b/SafeObject_zp/NSAttributedString+zp_Safe.h new file mode 100644 index 0000000..2bfced8 --- /dev/null +++ b/SafeObject_zp/NSAttributedString+zp_Safe.h @@ -0,0 +1,17 @@ +// +// NSAttributedString+zp_Safe.h +// SafeObjectCrash +// +// Created by admin on 2019/4/10. +// Copyright © 2019 lujh. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface NSAttributedString (zp_Safe) + +@end + +NS_ASSUME_NONNULL_END diff --git a/SafeObject_zp/NSAttributedString+zp_Safe.m b/SafeObject_zp/NSAttributedString+zp_Safe.m new file mode 100644 index 0000000..ac459f6 --- /dev/null +++ b/SafeObject_zp/NSAttributedString+zp_Safe.m @@ -0,0 +1,33 @@ +// +// NSAttributedString+zp_Safe.m +// SafeObjectCrash +// +// Created by admin on 2019/4/10. +// Copyright © 2019 lujh. All rights reserved. +// + +#import "NSAttributedString+zp_Safe.h" +#import + +@implementation NSAttributedString (zp_Safe) ++ (void)load{ + + Method oldMethod = class_getInstanceMethod(self, @selector(initWithString:attributes:)); + Method safeMethod = class_getInstanceMethod(self, @selector(safe_initWithString:attributes:)); + + method_exchangeImplementations(oldMethod, safeMethod); + + +} +- (instancetype)safe_initWithString:(NSString *)str attributes:(NSDictionary *)attrs{ + if (str.length <= 0) { +#ifdef DEBUG + NSAssert(str, @"Method (initWithString:attributes:) invlie:str"); +#else + str = @""; +#endif + + } + return [self safe_initWithString:str attributes:attrs]; +} +@end diff --git a/SafeObject/NSDictionary+Safe.h b/SafeObject_zp/NSDictionary+Safe.h similarity index 100% rename from SafeObject/NSDictionary+Safe.h rename to SafeObject_zp/NSDictionary+Safe.h diff --git a/SafeObject/NSDictionary+Safe.m b/SafeObject_zp/NSDictionary+Safe.m similarity index 100% rename from SafeObject/NSDictionary+Safe.m rename to SafeObject_zp/NSDictionary+Safe.m diff --git a/SafeObject/NSMutableArray+Safe.h b/SafeObject_zp/NSMutableArray+Safe.h similarity index 100% rename from SafeObject/NSMutableArray+Safe.h rename to SafeObject_zp/NSMutableArray+Safe.h diff --git a/SafeObject/NSMutableArray+Safe.m b/SafeObject_zp/NSMutableArray+Safe.m similarity index 100% rename from SafeObject/NSMutableArray+Safe.m rename to SafeObject_zp/NSMutableArray+Safe.m diff --git a/SafeObject_zp/NSMutableAttributedString+zp_Safe.h b/SafeObject_zp/NSMutableAttributedString+zp_Safe.h new file mode 100644 index 0000000..c7e4d63 --- /dev/null +++ b/SafeObject_zp/NSMutableAttributedString+zp_Safe.h @@ -0,0 +1,17 @@ +// +// NSMutableAttributedString+zp_Safe.h +// SafeObjectCrash +// +// Created by admin on 2019/4/10. +// Copyright © 2019 lujh. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface NSMutableAttributedString (zp_Safe) + +@end + +NS_ASSUME_NONNULL_END diff --git a/SafeObject_zp/NSMutableAttributedString+zp_Safe.m b/SafeObject_zp/NSMutableAttributedString+zp_Safe.m new file mode 100644 index 0000000..5ce7421 --- /dev/null +++ b/SafeObject_zp/NSMutableAttributedString+zp_Safe.m @@ -0,0 +1,33 @@ +// +// NSMutableAttributedString+zp_Safe.m +// SafeObjectCrash +// +// Created by admin on 2019/4/10. +// Copyright © 2019 lujh. All rights reserved. +// + +#import "NSMutableAttributedString+zp_Safe.h" +#import + +@implementation NSMutableAttributedString (zp_Safe) ++ (void)load{ + + Method oldMethod = class_getInstanceMethod(self, @selector(initWithString:attributes:)); + Method safeMethod = class_getInstanceMethod(self, @selector(safe_initWithString:attributes:)); + + method_exchangeImplementations(oldMethod, safeMethod); + + +} +- (instancetype)safe_initWithString:(NSString *)str attributes:(NSDictionary *)attrs{ + if (str.length <= 0) { +#ifdef DEBUG + NSAssert(str, @"Method (initWithString:attributes:) invlie:str"); +#else + str = @""; +#endif + + } + return [self safe_initWithString:str attributes:attrs]; +} +@end diff --git a/SafeObject/NSMutableDictionary+Safe.h b/SafeObject_zp/NSMutableDictionary+Safe.h similarity index 100% rename from SafeObject/NSMutableDictionary+Safe.h rename to SafeObject_zp/NSMutableDictionary+Safe.h diff --git a/SafeObject/NSMutableDictionary+Safe.m b/SafeObject_zp/NSMutableDictionary+Safe.m similarity index 100% rename from SafeObject/NSMutableDictionary+Safe.m rename to SafeObject_zp/NSMutableDictionary+Safe.m diff --git a/SafeObject/NSMutableString+Safe.h b/SafeObject_zp/NSMutableString+Safe.h similarity index 100% rename from SafeObject/NSMutableString+Safe.h rename to SafeObject_zp/NSMutableString+Safe.h diff --git a/SafeObject/NSMutableString+Safe.m b/SafeObject_zp/NSMutableString+Safe.m similarity index 100% rename from SafeObject/NSMutableString+Safe.m rename to SafeObject_zp/NSMutableString+Safe.m diff --git a/SafeObject/NSObject+ImpChangeTool.h b/SafeObject_zp/NSObject+ImpChangeTool.h similarity index 100% rename from SafeObject/NSObject+ImpChangeTool.h rename to SafeObject_zp/NSObject+ImpChangeTool.h diff --git a/SafeObject/NSObject+ImpChangeTool.m b/SafeObject_zp/NSObject+ImpChangeTool.m similarity index 100% rename from SafeObject/NSObject+ImpChangeTool.m rename to SafeObject_zp/NSObject+ImpChangeTool.m diff --git a/SafeObject/NSObject+Swizzling.h b/SafeObject_zp/NSObject+Swizzling.h similarity index 100% rename from SafeObject/NSObject+Swizzling.h rename to SafeObject_zp/NSObject+Swizzling.h diff --git a/SafeObject/NSObject+Swizzling.m b/SafeObject_zp/NSObject+Swizzling.m similarity index 100% rename from SafeObject/NSObject+Swizzling.m rename to SafeObject_zp/NSObject+Swizzling.m diff --git a/SafeObject/SafeObject.h b/SafeObject_zp/SafeObject.h similarity index 100% rename from SafeObject/SafeObject.h rename to SafeObject_zp/SafeObject.h