Skip to content

Commit

Permalink
更新工具类
Browse files Browse the repository at this point in the history
  • Loading branch information
ligang committed Nov 21, 2018
1 parent d8cc00c commit 7fc147b
Show file tree
Hide file tree
Showing 13 changed files with 525 additions and 609 deletions.
18 changes: 6 additions & 12 deletions LGApplications.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
CE008C131EE7FEB200318D98 /* LGPickerView.m in Sources */ = {isa = PBXBuildFile; fileRef = CE008C121EE7FEB200318D98 /* LGPickerView.m */; };
CE008C151EE800C000318D98 /* district.json in Resources */ = {isa = PBXBuildFile; fileRef = CE008C141EE800C000318D98 /* district.json */; };
CE008C181EE80E2300318D98 /* ActionSheetDemo.m in Sources */ = {isa = PBXBuildFile; fileRef = CE008C171EE80E2300318D98 /* ActionSheetDemo.m */; };
CE0F0C6920AD349200D4C8AF /* TextViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = CE0F0C6620AD349200D4C8AF /* TextViewCell.m */; };
CE0F0C6A20AD349200D4C8AF /* CommonCell.m in Sources */ = {isa = PBXBuildFile; fileRef = CE0F0C6820AD349200D4C8AF /* CommonCell.m */; };
CE1122781EE9396500C203DF /* SingleChoiceDemo.m in Sources */ = {isa = PBXBuildFile; fileRef = CE1122771EE9396500C203DF /* SingleChoiceDemo.m */; };
CE45DF0E20C5382000F33D4D /* KeyChainStore.m in Sources */ = {isa = PBXBuildFile; fileRef = CE45DF0C20C5382000F33D4D /* KeyChainStore.m */; };
CE6040D21EE5316E0089C945 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = CE6040D11EE5316E0089C945 /* main.m */; };
Expand All @@ -37,6 +35,7 @@
CEBFE427204E743900AEE96D /* HomeController.m in Sources */ = {isa = PBXBuildFile; fileRef = CEBFE423204E743900AEE96D /* HomeController.m */; };
CEBFE428204E743900AEE96D /* ListController.m in Sources */ = {isa = PBXBuildFile; fileRef = CEBFE424204E743900AEE96D /* ListController.m */; };
CED040FE1F63C99000C8B441 /* LGRollView.m in Sources */ = {isa = PBXBuildFile; fileRef = CED040FD1F63C99000C8B441 /* LGRollView.m */; };
CEDFD7F021A502A9000C0D4F /* IndexSectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = CEDFD7EF21A502A9000C0D4F /* IndexSectionView.m */; };
CEE768751EEA5A670093514F /* GradientAnimationDemo.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE768741EEA5A670093514F /* GradientAnimationDemo.m */; };
CEE768781EEA78620093514F /* LGGradientLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE768771EEA78620093514F /* LGGradientLabel.m */; };
CEF78A9E1F3D565400EF0507 /* LGInputView.m in Sources */ = {isa = PBXBuildFile; fileRef = CEF78A9D1F3D565400EF0507 /* LGInputView.m */; };
Expand Down Expand Up @@ -93,10 +92,6 @@
CE008C141EE800C000318D98 /* district.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = district.json; sourceTree = "<group>"; };
CE008C161EE80E2300318D98 /* ActionSheetDemo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ActionSheetDemo.h; sourceTree = "<group>"; };
CE008C171EE80E2300318D98 /* ActionSheetDemo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ActionSheetDemo.m; sourceTree = "<group>"; };
CE0F0C6520AD349100D4C8AF /* CommonCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonCell.h; sourceTree = "<group>"; };
CE0F0C6620AD349200D4C8AF /* TextViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TextViewCell.m; sourceTree = "<group>"; };
CE0F0C6720AD349200D4C8AF /* TextViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextViewCell.h; sourceTree = "<group>"; };
CE0F0C6820AD349200D4C8AF /* CommonCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommonCell.m; sourceTree = "<group>"; };
CE1122761EE9396500C203DF /* SingleChoiceDemo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SingleChoiceDemo.h; sourceTree = "<group>"; };
CE1122771EE9396500C203DF /* SingleChoiceDemo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SingleChoiceDemo.m; sourceTree = "<group>"; };
CE45DF0C20C5382000F33D4D /* KeyChainStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KeyChainStore.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -124,6 +119,8 @@
CEBFE426204E743900AEE96D /* ListController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ListController.h; sourceTree = "<group>"; };
CED040FC1F63C99000C8B441 /* LGRollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGRollView.h; sourceTree = "<group>"; };
CED040FD1F63C99000C8B441 /* LGRollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGRollView.m; sourceTree = "<group>"; };
CEDFD7EE21A502A9000C0D4F /* IndexSectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndexSectionView.h; sourceTree = "<group>"; };
CEDFD7EF21A502A9000C0D4F /* IndexSectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IndexSectionView.m; sourceTree = "<group>"; };
CEE768731EEA5A670093514F /* GradientAnimationDemo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GradientAnimationDemo.h; sourceTree = "<group>"; };
CEE768741EEA5A670093514F /* GradientAnimationDemo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GradientAnimationDemo.m; sourceTree = "<group>"; };
CEE768761EEA78620093514F /* LGGradientLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGGradientLabel.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -224,10 +221,8 @@
CE008BF71EE7CA7500318D98 /* LGViews */ = {
isa = PBXGroup;
children = (
CE0F0C6520AD349100D4C8AF /* CommonCell.h */,
CE0F0C6820AD349200D4C8AF /* CommonCell.m */,
CE0F0C6720AD349200D4C8AF /* TextViewCell.h */,
CE0F0C6620AD349200D4C8AF /* TextViewCell.m */,
CEDFD7EE21A502A9000C0D4F /* IndexSectionView.h */,
CEDFD7EF21A502A9000C0D4F /* IndexSectionView.m */,
CE9266261F22F9100063724B /* LGAlertView.h */,
CE9266271F22F9100063724B /* LGAlertView.m */,
CE008C111EE7FEB200318D98 /* LGPickerView.h */,
Expand Down Expand Up @@ -554,6 +549,7 @@
CE008BEF1EE7C95600318D98 /* NSString+Extension.m in Sources */,
CEBFE428204E743900AEE96D /* ListController.m in Sources */,
CE008C0D1EE7ED5A00318D98 /* PickerDemoController.m in Sources */,
CEDFD7F021A502A9000C0D4F /* IndexSectionView.m in Sources */,
CED040FE1F63C99000C8B441 /* LGRollView.m in Sources */,
CE008BF01EE7C95600318D98 /* UIButton+Extension.m in Sources */,
CE008BF51EE7CA3C00318D98 /* NSUtil.m in Sources */,
Expand All @@ -566,7 +562,6 @@
CE9266281F22F9100063724B /* LGAlertView.m in Sources */,
CE008C101EE7F64A00318D98 /* BaseController.m in Sources */,
CE008BF11EE7C95600318D98 /* UIView+Extension.m in Sources */,
CE0F0C6A20AD349200D4C8AF /* CommonCell.m in Sources */,
CEF78A9E1F3D565400EF0507 /* LGInputView.m in Sources */,
CEBFE427204E743900AEE96D /* HomeController.m in Sources */,
CE1122781EE9396500C203DF /* SingleChoiceDemo.m in Sources */,
Expand All @@ -576,7 +571,6 @@
CE6040D21EE5316E0089C945 /* main.m in Sources */,
CE008C131EE7FEB200318D98 /* LGPickerView.m in Sources */,
CEE768751EEA5A670093514F /* GradientAnimationDemo.m in Sources */,
CE0F0C6920AD349200D4C8AF /* TextViewCell.m in Sources */,
CE45DF0E20C5382000F33D4D /* KeyChainStore.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
3 changes: 2 additions & 1 deletion LGApplications/Util/Category/NSDictionary+Extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#import <Foundation/Foundation.h>

@interface NSDictionary (Extension)

- (NSString*)stringForKey:(NSString*)key;
- (NSDictionary *)removeNull;
@end


Expand Down
62 changes: 62 additions & 0 deletions LGApplications/Util/Category/NSDictionary+Extension.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,69 @@
#import "NSDictionary+Extension.h"

@implementation NSDictionary (Extension)
- (NSString*)stringForKey:(NSString*)key
{
id retObj = @"";

if ([self isKindOfClass:[NSDictionary class]]) {
NSDictionary *dict = (NSDictionary*)self;
retObj = [dict valueForKey:key];

if ([retObj isKindOfClass:[NSNumber class]]) {
retObj = [retObj stringValue];
}

if (![retObj isKindOfClass:[NSString class]]) {
retObj = [NSString string];
}
}
return retObj;
}



- (NSDictionary *)removeNull{

// 去除空值
NSMutableDictionary *dic = self.mutableCopy;
for (NSString * key in dic.allKeys) {
id value = [dic valueForKey:key];

// 字典里包含字典
if ([value isKindOfClass:[NSDictionary class]]) {
value = [value removeNull];
[dic setValue:value forKey:key];
}

// 如果是数组
else if ([value isKindOfClass:[NSArray class]]) {
NSMutableArray *array = [value mutableCopy];
for (int i= 0; i<array.count; i++) {

// 数组里包含字典
if ([array[i] isKindOfClass:[NSDictionary class]]) {
NSDictionary *dic = array[i];
dic = [dic removeNull];
[array replaceObjectAtIndex:i withObject:dic];
}
// 如果是空
else if (array[i] == nil || [array[i] isKindOfClass:[NSNull class]]) {
[array replaceObjectAtIndex:i withObject:@""];
}

}
[dic setValue:array forKey:key];
}

//
else if (value == nil || [value isKindOfClass:[NSNull class]]) {
value = @"";
[dic setValue:value forKey:key];
}
}

return dic;
}
#if DEBUG

- (NSString *)descriptionWithLocale:(id)locale indent:(NSUInteger)level
Expand Down
35 changes: 32 additions & 3 deletions LGApplications/Util/LGUtil/NSUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

typedef void(^StringBlock)(NSString *name);

typedef void(^ResultBlock)(NSDictionary *result);
typedef void(^StringBlock)(NSString *text);
typedef void(^CompleteBlock)(void);


typedef NS_ENUM(NSInteger, NetWorkStatus) {
Expand Down Expand Up @@ -48,6 +51,22 @@ typedef NS_ENUM(NSInteger, NetWorkType) {
/** 获取UUID*/
+ (NSString *)getUUIDByKeyChain;

#pragma mark - 在主线程执行某操作
+ (void)performBlockOnMainThread:(CompleteBlock)block;

#pragma mark - 返回当前类的所有属性
+ (instancetype)getProperties:(Class)className;

#pragma mark - 获取启动图
+ (UIImage *)getLaunchImage;

#pragma mark - 设置
/** 设置导航栏黑线*/
+ (void)setNavigationBarLine:(UIView *)view hidden:(BOOL)hidden;

#pragma mark - NSUserDefaults
+ (void)saveValue:(id)value forKey:(NSString *)key;
+ (id)getValueForKey:(NSString *)key;

#pragma mark - 文件管理(缓存) FileManager
/** 路径是否存在*/
Expand All @@ -65,9 +84,12 @@ typedef NS_ENUM(NSInteger, NetWorkType) {
/** Document下文件路径 没有时会创建一个*/
+ (NSString *)getDocumentFilePath:(NSString *)file;

/** Cache下文件路径 没有时会创建一个*/
/** Cache下文件路径(比如.plist) 没有时会创建一个*/
+ (NSString *)getCacheFilePath:(NSString *)file;

/** Cache下文件夹 没有时会创建一个*/
+ (NSString *)getCacheDirectory:(NSString *)directory;

/** 缓存大小*/
+ (unsigned long long)getCacheSize;

Expand All @@ -82,6 +104,12 @@ typedef NS_ENUM(NSInteger, NetWorkType) {
/** 判断是否为国内手机号码*/
+ (BOOL)isPhoneNumberInChina:(NSString *)phoneNumber;

/** 密码校验
* 密码长度最少6位
* 大写字母,小写字母,数字,特殊符号四选二
*/
+ (BOOL)checkPassword:(NSString *)password;

/** 判断是否是邮箱地址*/
+ (BOOL)isEmailAddress:(NSString *)email;

Expand Down Expand Up @@ -124,9 +152,10 @@ typedef NS_ENUM(NSInteger, NetWorkType) {
/** 压缩图片成Data*/
+ (NSData *)dataWithOriginalImage:(UIImage *)image;


#pragma mark - Font
/** bold为YES: 在指定的字体名没有对应字体的时 使用系统粗体*/
+ (UIFont *)fontWithName:(NSString *)name size:(CGFloat)size bold:(BOOL)bold;
+ (UIFont *)fontWithFamily:(NSString *)family name:(NSString *)name size:(CGFloat)size;
@end

@end
Loading

0 comments on commit 7fc147b

Please sign in to comment.