Skip to content

Commit b50025a

Browse files
committed
OC,load和initialize方法
1 parent 8c847c0 commit b50025a

File tree

8 files changed

+410
-0
lines changed

8 files changed

+410
-0
lines changed

load/Other.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// Normal.h
3+
// load
4+
//
5+
// Created by 张星宇 on 16/2/1.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface Other : NSObject
12+
13+
+ (void)printName;
14+
15+
@end

load/Other.m

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Normal.m
3+
// load
4+
//
5+
// Created by 张星宇 on 16/2/1.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
#import "Other.h"
10+
11+
@implementation Other
12+
13+
static NSString *name;
14+
15+
+ (void)load {
16+
name = @"Other";
17+
NSLog(@"Load Class Normal");
18+
}
19+
20+
+ (void)printName {
21+
NSLog(@"%@",name);
22+
}
23+
24+
@end

load/load.xcodeproj/project.pbxproj

+262
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
// !$*UTF8*$!
2+
{
3+
archiveVersion = 1;
4+
classes = {
5+
};
6+
objectVersion = 46;
7+
objects = {
8+
9+
/* Begin PBXBuildFile section */
10+
9B8E43CB1C5F6E40002ABEBC /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B8E43CA1C5F6E40002ABEBC /* main.m */; };
11+
9B8E43D31C5F6E78002ABEBC /* Parent.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B8E43D21C5F6E78002ABEBC /* Parent.m */; };
12+
9B8E43D61C5F6E7E002ABEBC /* Child.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B8E43D51C5F6E7E002ABEBC /* Child.m */; };
13+
9B8E43D91C5F7070002ABEBC /* Other.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B8E43D81C5F7070002ABEBC /* Other.m */; };
14+
/* End PBXBuildFile section */
15+
16+
/* Begin PBXCopyFilesBuildPhase section */
17+
9B8E43C51C5F6E40002ABEBC /* CopyFiles */ = {
18+
isa = PBXCopyFilesBuildPhase;
19+
buildActionMask = 2147483647;
20+
dstPath = /usr/share/man/man1/;
21+
dstSubfolderSpec = 0;
22+
files = (
23+
);
24+
runOnlyForDeploymentPostprocessing = 1;
25+
};
26+
/* End PBXCopyFilesBuildPhase section */
27+
28+
/* Begin PBXFileReference section */
29+
9B8E43C71C5F6E40002ABEBC /* load */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = load; sourceTree = BUILT_PRODUCTS_DIR; };
30+
9B8E43CA1C5F6E40002ABEBC /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
31+
9B8E43D11C5F6E78002ABEBC /* Parent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Parent.h; sourceTree = "<group>"; };
32+
9B8E43D21C5F6E78002ABEBC /* Parent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Parent.m; sourceTree = "<group>"; };
33+
9B8E43D41C5F6E7E002ABEBC /* Child.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Child.h; sourceTree = "<group>"; };
34+
9B8E43D51C5F6E7E002ABEBC /* Child.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Child.m; sourceTree = "<group>"; };
35+
9B8E43D71C5F7070002ABEBC /* Other.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Other.h; path = ../Other.h; sourceTree = "<group>"; };
36+
9B8E43D81C5F7070002ABEBC /* Other.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Other.m; path = ../Other.m; sourceTree = "<group>"; };
37+
/* End PBXFileReference section */
38+
39+
/* Begin PBXFrameworksBuildPhase section */
40+
9B8E43C41C5F6E40002ABEBC /* Frameworks */ = {
41+
isa = PBXFrameworksBuildPhase;
42+
buildActionMask = 2147483647;
43+
files = (
44+
);
45+
runOnlyForDeploymentPostprocessing = 0;
46+
};
47+
/* End PBXFrameworksBuildPhase section */
48+
49+
/* Begin PBXGroup section */
50+
9B8E43BE1C5F6E40002ABEBC = {
51+
isa = PBXGroup;
52+
children = (
53+
9B8E43C91C5F6E40002ABEBC /* load */,
54+
9B8E43C81C5F6E40002ABEBC /* Products */,
55+
);
56+
sourceTree = "<group>";
57+
};
58+
9B8E43C81C5F6E40002ABEBC /* Products */ = {
59+
isa = PBXGroup;
60+
children = (
61+
9B8E43C71C5F6E40002ABEBC /* load */,
62+
);
63+
name = Products;
64+
sourceTree = "<group>";
65+
};
66+
9B8E43C91C5F6E40002ABEBC /* load */ = {
67+
isa = PBXGroup;
68+
children = (
69+
9B8E43CA1C5F6E40002ABEBC /* main.m */,
70+
9B8E43D71C5F7070002ABEBC /* Other.h */,
71+
9B8E43D81C5F7070002ABEBC /* Other.m */,
72+
9B8E43D11C5F6E78002ABEBC /* Parent.h */,
73+
9B8E43D21C5F6E78002ABEBC /* Parent.m */,
74+
9B8E43D41C5F6E7E002ABEBC /* Child.h */,
75+
9B8E43D51C5F6E7E002ABEBC /* Child.m */,
76+
);
77+
path = load;
78+
sourceTree = "<group>";
79+
};
80+
/* End PBXGroup section */
81+
82+
/* Begin PBXNativeTarget section */
83+
9B8E43C61C5F6E40002ABEBC /* load */ = {
84+
isa = PBXNativeTarget;
85+
buildConfigurationList = 9B8E43CE1C5F6E40002ABEBC /* Build configuration list for PBXNativeTarget "load" */;
86+
buildPhases = (
87+
9B8E43C31C5F6E40002ABEBC /* Sources */,
88+
9B8E43C41C5F6E40002ABEBC /* Frameworks */,
89+
9B8E43C51C5F6E40002ABEBC /* CopyFiles */,
90+
);
91+
buildRules = (
92+
);
93+
dependencies = (
94+
);
95+
name = load;
96+
productName = load;
97+
productReference = 9B8E43C71C5F6E40002ABEBC /* load */;
98+
productType = "com.apple.product-type.tool";
99+
};
100+
/* End PBXNativeTarget section */
101+
102+
/* Begin PBXProject section */
103+
9B8E43BF1C5F6E40002ABEBC /* Project object */ = {
104+
isa = PBXProject;
105+
attributes = {
106+
LastUpgradeCheck = 0720;
107+
ORGANIZATIONNAME = zxy;
108+
TargetAttributes = {
109+
9B8E43C61C5F6E40002ABEBC = {
110+
CreatedOnToolsVersion = 7.2;
111+
};
112+
};
113+
};
114+
buildConfigurationList = 9B8E43C21C5F6E40002ABEBC /* Build configuration list for PBXProject "load" */;
115+
compatibilityVersion = "Xcode 3.2";
116+
developmentRegion = English;
117+
hasScannedForEncodings = 0;
118+
knownRegions = (
119+
en,
120+
);
121+
mainGroup = 9B8E43BE1C5F6E40002ABEBC;
122+
productRefGroup = 9B8E43C81C5F6E40002ABEBC /* Products */;
123+
projectDirPath = "";
124+
projectRoot = "";
125+
targets = (
126+
9B8E43C61C5F6E40002ABEBC /* load */,
127+
);
128+
};
129+
/* End PBXProject section */
130+
131+
/* Begin PBXSourcesBuildPhase section */
132+
9B8E43C31C5F6E40002ABEBC /* Sources */ = {
133+
isa = PBXSourcesBuildPhase;
134+
buildActionMask = 2147483647;
135+
files = (
136+
9B8E43CB1C5F6E40002ABEBC /* main.m in Sources */,
137+
9B8E43D61C5F6E7E002ABEBC /* Child.m in Sources */,
138+
9B8E43D31C5F6E78002ABEBC /* Parent.m in Sources */,
139+
9B8E43D91C5F7070002ABEBC /* Other.m in Sources */,
140+
);
141+
runOnlyForDeploymentPostprocessing = 0;
142+
};
143+
/* End PBXSourcesBuildPhase section */
144+
145+
/* Begin XCBuildConfiguration section */
146+
9B8E43CC1C5F6E40002ABEBC /* Debug */ = {
147+
isa = XCBuildConfiguration;
148+
buildSettings = {
149+
ALWAYS_SEARCH_USER_PATHS = NO;
150+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
151+
CLANG_CXX_LIBRARY = "libc++";
152+
CLANG_ENABLE_MODULES = YES;
153+
CLANG_ENABLE_OBJC_ARC = YES;
154+
CLANG_WARN_BOOL_CONVERSION = YES;
155+
CLANG_WARN_CONSTANT_CONVERSION = YES;
156+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
157+
CLANG_WARN_EMPTY_BODY = YES;
158+
CLANG_WARN_ENUM_CONVERSION = YES;
159+
CLANG_WARN_INT_CONVERSION = YES;
160+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
161+
CLANG_WARN_UNREACHABLE_CODE = YES;
162+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
163+
CODE_SIGN_IDENTITY = "-";
164+
COPY_PHASE_STRIP = NO;
165+
DEBUG_INFORMATION_FORMAT = dwarf;
166+
ENABLE_STRICT_OBJC_MSGSEND = YES;
167+
ENABLE_TESTABILITY = YES;
168+
GCC_C_LANGUAGE_STANDARD = gnu99;
169+
GCC_DYNAMIC_NO_PIC = NO;
170+
GCC_NO_COMMON_BLOCKS = YES;
171+
GCC_OPTIMIZATION_LEVEL = 0;
172+
GCC_PREPROCESSOR_DEFINITIONS = (
173+
"DEBUG=1",
174+
"$(inherited)",
175+
);
176+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
177+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
178+
GCC_WARN_UNDECLARED_SELECTOR = YES;
179+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
180+
GCC_WARN_UNUSED_FUNCTION = YES;
181+
GCC_WARN_UNUSED_VARIABLE = YES;
182+
MACOSX_DEPLOYMENT_TARGET = 10.11;
183+
MTL_ENABLE_DEBUG_INFO = YES;
184+
ONLY_ACTIVE_ARCH = YES;
185+
SDKROOT = macosx;
186+
};
187+
name = Debug;
188+
};
189+
9B8E43CD1C5F6E40002ABEBC /* Release */ = {
190+
isa = XCBuildConfiguration;
191+
buildSettings = {
192+
ALWAYS_SEARCH_USER_PATHS = NO;
193+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
194+
CLANG_CXX_LIBRARY = "libc++";
195+
CLANG_ENABLE_MODULES = YES;
196+
CLANG_ENABLE_OBJC_ARC = YES;
197+
CLANG_WARN_BOOL_CONVERSION = YES;
198+
CLANG_WARN_CONSTANT_CONVERSION = YES;
199+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
200+
CLANG_WARN_EMPTY_BODY = YES;
201+
CLANG_WARN_ENUM_CONVERSION = YES;
202+
CLANG_WARN_INT_CONVERSION = YES;
203+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
204+
CLANG_WARN_UNREACHABLE_CODE = YES;
205+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
206+
CODE_SIGN_IDENTITY = "-";
207+
COPY_PHASE_STRIP = NO;
208+
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
209+
ENABLE_NS_ASSERTIONS = NO;
210+
ENABLE_STRICT_OBJC_MSGSEND = YES;
211+
GCC_C_LANGUAGE_STANDARD = gnu99;
212+
GCC_NO_COMMON_BLOCKS = YES;
213+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
214+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
215+
GCC_WARN_UNDECLARED_SELECTOR = YES;
216+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
217+
GCC_WARN_UNUSED_FUNCTION = YES;
218+
GCC_WARN_UNUSED_VARIABLE = YES;
219+
MACOSX_DEPLOYMENT_TARGET = 10.11;
220+
MTL_ENABLE_DEBUG_INFO = NO;
221+
SDKROOT = macosx;
222+
};
223+
name = Release;
224+
};
225+
9B8E43CF1C5F6E40002ABEBC /* Debug */ = {
226+
isa = XCBuildConfiguration;
227+
buildSettings = {
228+
PRODUCT_NAME = "$(TARGET_NAME)";
229+
};
230+
name = Debug;
231+
};
232+
9B8E43D01C5F6E40002ABEBC /* Release */ = {
233+
isa = XCBuildConfiguration;
234+
buildSettings = {
235+
PRODUCT_NAME = "$(TARGET_NAME)";
236+
};
237+
name = Release;
238+
};
239+
/* End XCBuildConfiguration section */
240+
241+
/* Begin XCConfigurationList section */
242+
9B8E43C21C5F6E40002ABEBC /* Build configuration list for PBXProject "load" */ = {
243+
isa = XCConfigurationList;
244+
buildConfigurations = (
245+
9B8E43CC1C5F6E40002ABEBC /* Debug */,
246+
9B8E43CD1C5F6E40002ABEBC /* Release */,
247+
);
248+
defaultConfigurationIsVisible = 0;
249+
defaultConfigurationName = Release;
250+
};
251+
9B8E43CE1C5F6E40002ABEBC /* Build configuration list for PBXNativeTarget "load" */ = {
252+
isa = XCConfigurationList;
253+
buildConfigurations = (
254+
9B8E43CF1C5F6E40002ABEBC /* Debug */,
255+
9B8E43D01C5F6E40002ABEBC /* Release */,
256+
);
257+
defaultConfigurationIsVisible = 0;
258+
};
259+
/* End XCConfigurationList section */
260+
};
261+
rootObject = 9B8E43BF1C5F6E40002ABEBC /* Project object */;
262+
}

load/load/Child.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Child.h
3+
// load
4+
//
5+
// Created by 张星宇 on 16/2/1.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "Parent.h"
11+
12+
@interface Child : Parent
13+
14+
@end

load/load/Child.m

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// Child.m
3+
// load
4+
//
5+
// Created by 张星宇 on 16/2/1.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
#import "Child.h"
10+
#import "Other.h"
11+
12+
@implementation Child
13+
14+
+ (void)load {
15+
NSLog(@"Load Class Child");
16+
17+
Other *normal = [[Other alloc] init];
18+
NSLog(@"%@",normal);
19+
20+
// 如果不先调用Normal的load,下面这行代码就无效,打印出null
21+
[Other printName];
22+
}
23+
24+
//+ (void)initialize {
25+
// NSLog(@"Initialize Child, caller Class %@", [self class]);
26+
//}
27+
28+
@end

load/load/Parent.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Parent.h
3+
// load
4+
//
5+
// Created by 张星宇 on 16/2/1.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface Parent : NSObject
12+
13+
@end

load/load/Parent.m

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// Parent.m
3+
// load
4+
//
5+
// Created by 张星宇 on 16/2/1.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
#import "Parent.h"
10+
11+
static int someNumber = 0;
12+
static NSMutableArray *someObjects;
13+
14+
@implementation Parent
15+
16+
+ (void)load {
17+
NSLog(@"Load Class Parent");
18+
}
19+
20+
//+ (void)initialize {
21+
// NSLog(@"Initialize Parent, caller Class %@", [self class]);
22+
//}
23+
24+
/**
25+
* 下面这个才是正确的initialize方法的实现,需要判断是不是由自己这个类调用的。
26+
*/
27+
+ (void)initializeCorrect {
28+
if (self == [Parent class]) {
29+
someObjects = [[NSMutableArray alloc] init]; // 不方便编译期复制的对象在这里赋值
30+
NSLog(@"Initialize Parent, caller Class %@", [self class]);
31+
}
32+
}
33+
34+
@end

0 commit comments

Comments
 (0)