Skip to content

Commit 8e4a0a5

Browse files
committed
Initialize code
Initialize code
0 parents  commit 8e4a0a5

33 files changed

+1879
-0
lines changed

MJExtensionExample/MJExtensionExample.xcodeproj/project.pbxproj

+342
Large diffs are not rendered by default.

MJExtensionExample/MJExtensionExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0510"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "2D9CAF26192FA6020011F500"
18+
BuildableName = "MJExtensionExample"
19+
BlueprintName = "MJExtensionExample"
20+
ReferencedContainer = "container:MJExtensionExample.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
27+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
28+
shouldUseLaunchSchemeArgsEnv = "YES"
29+
buildConfiguration = "Debug">
30+
<Testables>
31+
</Testables>
32+
<MacroExpansion>
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "2D9CAF26192FA6020011F500"
36+
BuildableName = "MJExtensionExample"
37+
BlueprintName = "MJExtensionExample"
38+
ReferencedContainer = "container:MJExtensionExample.xcodeproj">
39+
</BuildableReference>
40+
</MacroExpansion>
41+
</TestAction>
42+
<LaunchAction
43+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
44+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
45+
launchStyle = "0"
46+
useCustomWorkingDirectory = "NO"
47+
buildConfiguration = "Debug"
48+
ignoresPersistentStateOnLaunch = "NO"
49+
debugDocumentVersioning = "YES"
50+
allowLocationSimulation = "YES">
51+
<BuildableProductRunnable>
52+
<BuildableReference
53+
BuildableIdentifier = "primary"
54+
BlueprintIdentifier = "2D9CAF26192FA6020011F500"
55+
BuildableName = "MJExtensionExample"
56+
BlueprintName = "MJExtensionExample"
57+
ReferencedContainer = "container:MJExtensionExample.xcodeproj">
58+
</BuildableReference>
59+
</BuildableProductRunnable>
60+
<AdditionalOptions>
61+
</AdditionalOptions>
62+
</LaunchAction>
63+
<ProfileAction
64+
shouldUseLaunchSchemeArgsEnv = "YES"
65+
savedToolIdentifier = ""
66+
useCustomWorkingDirectory = "NO"
67+
buildConfiguration = "Release"
68+
debugDocumentVersioning = "YES">
69+
<BuildableProductRunnable>
70+
<BuildableReference
71+
BuildableIdentifier = "primary"
72+
BlueprintIdentifier = "2D9CAF26192FA6020011F500"
73+
BuildableName = "MJExtensionExample"
74+
BlueprintName = "MJExtensionExample"
75+
ReferencedContainer = "container:MJExtensionExample.xcodeproj">
76+
</BuildableReference>
77+
</BuildableProductRunnable>
78+
</ProfileAction>
79+
<AnalyzeAction
80+
buildConfiguration = "Debug">
81+
</AnalyzeAction>
82+
<ArchiveAction
83+
buildConfiguration = "Release"
84+
revealArchiveInOrganizer = "YES">
85+
</ArchiveAction>
86+
</Scheme>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>MJExtensionExample.xcscheme</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
</dict>
13+
<key>SuppressBuildableAutocreation</key>
14+
<dict>
15+
<key>2D9CAF26192FA6020011F500</key>
16+
<dict>
17+
<key>primary</key>
18+
<true/>
19+
</dict>
20+
</dict>
21+
</dict>
22+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// MJArgument.h
3+
// ItcastWeibo
4+
//
5+
// Created by mj on 14-1-15.
6+
// Copyright (c) 2014年 itcast. All rights reserved.
7+
// 包装一个方法参数
8+
9+
#import <Foundation/Foundation.h>
10+
/**
11+
* 包装一个方法参数
12+
*/
13+
@interface MJArgument : NSObject
14+
/** 参数的索引 */
15+
@property (nonatomic, assign) int index;
16+
/** 参数类型 */
17+
@property (nonatomic, copy) NSString *type;
18+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// MJArgument.m
3+
// ItcastWeibo
4+
//
5+
// Created by mj on 14-1-15.
6+
// Copyright (c) 2014年 itcast. All rights reserved.
7+
//
8+
9+
#import "MJArgument.h"
10+
#import "MJExtension.h"
11+
12+
@implementation MJArgument
13+
MJLogAllIvrs
14+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// MJExtension.h
3+
// MJExtension
4+
//
5+
// Created by mj on 14-1-15.
6+
// Copyright (c) 2014年 itcast. All rights reserved.
7+
//
8+
9+
#import "MJTypeEncoding.h"
10+
#import "NSObject+MJCoding.h"
11+
#import "NSObject+MJMember.h"
12+
#import "NSObject+MJKeyValue.h"
13+
14+
#define MJLogAllIvrs \
15+
- (NSString *)description \
16+
{ \
17+
return [self keyValues].description; \
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// MJIvar.h
3+
// MJExtension
4+
//
5+
// Created by mj on 14-1-15.
6+
// Copyright (c) 2014年 itcast. All rights reserved.
7+
// 包装一个成员变量
8+
9+
#import "MJMember.h"
10+
@class MJType;
11+
12+
/**
13+
* 包装一个成员变量
14+
*/
15+
@interface MJIvar : MJMember
16+
/** 成员变量 */
17+
@property (nonatomic, assign) Ivar ivar;
18+
/** 成员属性名 */
19+
@property (nonatomic, copy, readonly) NSString *propertyName;
20+
/** 成员变量的值 */
21+
@property (nonatomic) id value;
22+
/** 成员变量的类型 */
23+
@property (nonatomic, strong, readonly) MJType *type;
24+
25+
/**
26+
* 初始化
27+
*
28+
* @param ivar 成员变量
29+
* @param srcObject 哪个对象的成员变量
30+
*
31+
* @return 初始化好的对象
32+
*/
33+
- (instancetype)initWithIvar:(Ivar)ivar srcObject:(id)srcObject;
34+
@end
35+
36+
/**
37+
* 遍历成员变量用的block
38+
*
39+
* @param ivar 成员变量的包装对象
40+
* @param stop YES代表停止遍历,NO代表继续遍历
41+
*/
42+
typedef void (^MJIvarsBlock)(MJIvar *ivar, BOOL *stop);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// MJIvar.m
3+
// MJExtension
4+
//
5+
// Created by mj on 14-1-15.
6+
// Copyright (c) 2014年 itcast. All rights reserved.
7+
//
8+
9+
#import "MJIvar.h"
10+
#import "MJTypeEncoding.h"
11+
12+
@implementation MJIvar
13+
/**
14+
* 初始化
15+
*
16+
* @param ivar 成员变量
17+
* @param srcObject 哪个对象的成员变量
18+
*
19+
* @return 初始化好的对象
20+
*/
21+
- (instancetype)initWithIvar:(Ivar)ivar srcObject:(id)srcObject
22+
{
23+
if (self = [super initWithSrcObject:srcObject]) {
24+
self.ivar = ivar;
25+
}
26+
return self;
27+
}
28+
29+
/**
30+
* 设置成员变量
31+
*/
32+
- (void)setIvar:(Ivar)ivar
33+
{
34+
_ivar = ivar;
35+
36+
// 1.成员变量名
37+
_name = [NSString stringWithUTF8String:ivar_getName(ivar)];
38+
39+
// 2.属性名
40+
if ([_name hasPrefix:@"_"]) {
41+
_propertyName = [_name stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@""];
42+
} else {
43+
_propertyName = _name;
44+
}
45+
46+
// 3.成员变量的类型符
47+
NSString *code = [NSString stringWithUTF8String:ivar_getTypeEncoding(ivar)];
48+
// NSLog(@"---%@-%@---", _name, code);
49+
_type = [[MJType alloc] initWithCode:code];
50+
}
51+
52+
/**
53+
* 获得成员变量的值
54+
*/
55+
- (id)value
56+
{
57+
if (_type.KVCDisabled) return [NSNull null];
58+
return [_srcObject valueForKey:_propertyName];
59+
}
60+
61+
/**
62+
* 设置成员变量的值
63+
*/
64+
- (void)setValue:(id)value
65+
{
66+
if (_type.KVCDisabled) return;
67+
[_srcObject setValue:value forKey:_propertyName];
68+
}
69+
70+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// MJMember.h
3+
// MJExtension
4+
//
5+
// Created by mj on 14-1-15.
6+
// Copyright (c) 2014年 itcast. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import <objc/message.h>
11+
#import "MJType.h"
12+
#import "MJArgument.h"
13+
14+
@interface MJMember : NSObject
15+
{
16+
__weak id _srcObject;
17+
Class _srcClass;
18+
NSString *_name;
19+
}
20+
/** 成员来源于哪个类(可能是父类) */
21+
@property (nonatomic, assign) Class srcClass;
22+
/** 成员来源类是否是Foundation框架的 */
23+
@property (nonatomic, readonly, getter = isSrcClassFromFoundation) BOOL srcClassFromFoundation;
24+
25+
/** 成员来源于哪个对象 */
26+
@property (nonatomic, weak, readonly) id srcObject;
27+
28+
/** 成员名 */
29+
@property (nonatomic, copy, readonly) NSString *name;
30+
31+
/**
32+
* 初始化
33+
*
34+
* @param srcObject 来源于哪个对象
35+
*
36+
* @return 初始化好的对象
37+
*/
38+
- (instancetype)initWithSrcObject:(id)srcObject;
39+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// MJMember.m
3+
// MJExtension
4+
//
5+
// Created by mj on 14-1-15.
6+
// Copyright (c) 2014年 itcast. All rights reserved.
7+
//
8+
9+
#import "MJMember.h"
10+
#import "MJExtension.h"
11+
12+
@implementation MJMember
13+
/**
14+
* 初始化
15+
*
16+
* @param srcObject 来源于哪个对象
17+
*
18+
* @return 初始化好的对象
19+
*/
20+
- (instancetype)initWithSrcObject:(id)srcObject
21+
{
22+
if (self = [super init]) {
23+
_srcObject = srcObject;
24+
}
25+
return self;
26+
}
27+
28+
- (void)setSrcClass:(Class)srcClass
29+
{
30+
_srcClass = srcClass;
31+
32+
_srcClassFromFoundation = [NSStringFromClass(srcClass) hasPrefix:@"NS"];
33+
}
34+
35+
MJLogAllIvrs
36+
@end

0 commit comments

Comments
 (0)