├── .gitignore ├── LICENSE ├── README.md ├── RuntimeDemo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── RuntimeDemo ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── Message.h ├── Message.m ├── MessageForwarding.h ├── MessageForwarding.m ├── MessageForwarding~.h ├── NSObject+AssociatedObject.h ├── NSObject+AssociatedObject.m ├── UIViewController+Logging.h ├── UIViewController+Logging.m ├── ViewController.h ├── ViewController.m └── main.m └── RuntimeDemoTests ├── Info.plist └── RuntimeDemoTests.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | #Pods/ 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Sam Lau 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RuntimeDemo 2 | Objective-C Runtime机制的示例代码,包含以下例子: 3 | 4 | * 方法解析和消息转发 - Message和MessageForwarding类 5 | * Associated Objects : NSObject+AssociatedObject Category 6 | * Method Swizzling:UIViewController+Logging Category 7 | 8 | -------------------------------------------------------------------------------- /RuntimeDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1A04A2811B4927E4003DE2A4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A04A2801B4927E4003DE2A4 /* main.m */; }; 11 | 1A04A2841B4927E4003DE2A4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A04A2831B4927E4003DE2A4 /* AppDelegate.m */; }; 12 | 1A04A2871B4927E4003DE2A4 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A04A2861B4927E4003DE2A4 /* ViewController.m */; }; 13 | 1A04A28A1B4927E4003DE2A4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1A04A2881B4927E4003DE2A4 /* Main.storyboard */; }; 14 | 1A04A28C1B4927E4003DE2A4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1A04A28B1B4927E4003DE2A4 /* Assets.xcassets */; }; 15 | 1A04A28F1B4927E4003DE2A4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1A04A28D1B4927E4003DE2A4 /* LaunchScreen.storyboard */; }; 16 | 1A04A29A1B4927E5003DE2A4 /* RuntimeDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A04A2991B4927E5003DE2A4 /* RuntimeDemoTests.m */; }; 17 | 1A04A2A61B492816003DE2A4 /* Message.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A04A2A51B492816003DE2A4 /* Message.m */; }; 18 | 1AADFBD21B49306900E4B5C8 /* MessageForwarding.m in Sources */ = {isa = PBXBuildFile; fileRef = 1AADFBD11B49306900E4B5C8 /* MessageForwarding.m */; }; 19 | 1AF7BEE91B49524E003A0216 /* NSObject+AssociatedObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 1AF7BEE81B49524E003A0216 /* NSObject+AssociatedObject.m */; }; 20 | 1AF7BEEC1B495D8B003A0216 /* UIViewController+Logging.m in Sources */ = {isa = PBXBuildFile; fileRef = 1AF7BEEB1B495D8B003A0216 /* UIViewController+Logging.m */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 1A04A2961B4927E5003DE2A4 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 1A04A2741B4927E4003DE2A4 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 1A04A27B1B4927E4003DE2A4; 29 | remoteInfo = RuntimeDemo; 30 | }; 31 | /* End PBXContainerItemProxy section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | 1A04A27C1B4927E4003DE2A4 /* RuntimeDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RuntimeDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | 1A04A2801B4927E4003DE2A4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 36 | 1A04A2821B4927E4003DE2A4 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 37 | 1A04A2831B4927E4003DE2A4 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 38 | 1A04A2851B4927E4003DE2A4 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 39 | 1A04A2861B4927E4003DE2A4 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 40 | 1A04A2891B4927E4003DE2A4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 41 | 1A04A28B1B4927E4003DE2A4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 42 | 1A04A28E1B4927E4003DE2A4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 43 | 1A04A2901B4927E4003DE2A4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 44 | 1A04A2951B4927E5003DE2A4 /* RuntimeDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RuntimeDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | 1A04A2991B4927E5003DE2A4 /* RuntimeDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RuntimeDemoTests.m; sourceTree = ""; }; 46 | 1A04A29B1B4927E5003DE2A4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 47 | 1A04A2A41B492816003DE2A4 /* Message.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Message.h; sourceTree = ""; }; 48 | 1A04A2A51B492816003DE2A4 /* Message.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Message.m; sourceTree = ""; }; 49 | 1AADFBD01B49306900E4B5C8 /* MessageForwarding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageForwarding.h; sourceTree = ""; }; 50 | 1AADFBD11B49306900E4B5C8 /* MessageForwarding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MessageForwarding.m; sourceTree = ""; }; 51 | 1AF7BEE71B49524E003A0216 /* NSObject+AssociatedObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+AssociatedObject.h"; sourceTree = ""; }; 52 | 1AF7BEE81B49524E003A0216 /* NSObject+AssociatedObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+AssociatedObject.m"; sourceTree = ""; }; 53 | 1AF7BEEA1B495D8B003A0216 /* UIViewController+Logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+Logging.h"; sourceTree = ""; }; 54 | 1AF7BEEB1B495D8B003A0216 /* UIViewController+Logging.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Logging.m"; sourceTree = ""; }; 55 | /* End PBXFileReference section */ 56 | 57 | /* Begin PBXFrameworksBuildPhase section */ 58 | 1A04A2791B4927E4003DE2A4 /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | ); 63 | runOnlyForDeploymentPostprocessing = 0; 64 | }; 65 | 1A04A2921B4927E5003DE2A4 /* Frameworks */ = { 66 | isa = PBXFrameworksBuildPhase; 67 | buildActionMask = 2147483647; 68 | files = ( 69 | ); 70 | runOnlyForDeploymentPostprocessing = 0; 71 | }; 72 | /* End PBXFrameworksBuildPhase section */ 73 | 74 | /* Begin PBXGroup section */ 75 | 1A04A2731B4927E4003DE2A4 = { 76 | isa = PBXGroup; 77 | children = ( 78 | 1A04A27E1B4927E4003DE2A4 /* RuntimeDemo */, 79 | 1A04A2981B4927E5003DE2A4 /* RuntimeDemoTests */, 80 | 1A04A27D1B4927E4003DE2A4 /* Products */, 81 | ); 82 | sourceTree = ""; 83 | }; 84 | 1A04A27D1B4927E4003DE2A4 /* Products */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 1A04A27C1B4927E4003DE2A4 /* RuntimeDemo.app */, 88 | 1A04A2951B4927E5003DE2A4 /* RuntimeDemoTests.xctest */, 89 | ); 90 | name = Products; 91 | sourceTree = ""; 92 | }; 93 | 1A04A27E1B4927E4003DE2A4 /* RuntimeDemo */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 1A04A2821B4927E4003DE2A4 /* AppDelegate.h */, 97 | 1A04A2831B4927E4003DE2A4 /* AppDelegate.m */, 98 | 1A04A2851B4927E4003DE2A4 /* ViewController.h */, 99 | 1A04A2861B4927E4003DE2A4 /* ViewController.m */, 100 | 1A04A2A41B492816003DE2A4 /* Message.h */, 101 | 1A04A2A51B492816003DE2A4 /* Message.m */, 102 | 1AADFBD01B49306900E4B5C8 /* MessageForwarding.h */, 103 | 1AADFBD11B49306900E4B5C8 /* MessageForwarding.m */, 104 | 1AF7BEE71B49524E003A0216 /* NSObject+AssociatedObject.h */, 105 | 1AF7BEE81B49524E003A0216 /* NSObject+AssociatedObject.m */, 106 | 1AF7BEEA1B495D8B003A0216 /* UIViewController+Logging.h */, 107 | 1AF7BEEB1B495D8B003A0216 /* UIViewController+Logging.m */, 108 | 1A04A2881B4927E4003DE2A4 /* Main.storyboard */, 109 | 1A04A28B1B4927E4003DE2A4 /* Assets.xcassets */, 110 | 1A04A28D1B4927E4003DE2A4 /* LaunchScreen.storyboard */, 111 | 1A04A2901B4927E4003DE2A4 /* Info.plist */, 112 | 1A04A27F1B4927E4003DE2A4 /* Supporting Files */, 113 | ); 114 | path = RuntimeDemo; 115 | sourceTree = ""; 116 | }; 117 | 1A04A27F1B4927E4003DE2A4 /* Supporting Files */ = { 118 | isa = PBXGroup; 119 | children = ( 120 | 1A04A2801B4927E4003DE2A4 /* main.m */, 121 | ); 122 | name = "Supporting Files"; 123 | sourceTree = ""; 124 | }; 125 | 1A04A2981B4927E5003DE2A4 /* RuntimeDemoTests */ = { 126 | isa = PBXGroup; 127 | children = ( 128 | 1A04A2991B4927E5003DE2A4 /* RuntimeDemoTests.m */, 129 | 1A04A29B1B4927E5003DE2A4 /* Info.plist */, 130 | ); 131 | path = RuntimeDemoTests; 132 | sourceTree = ""; 133 | }; 134 | /* End PBXGroup section */ 135 | 136 | /* Begin PBXNativeTarget section */ 137 | 1A04A27B1B4927E4003DE2A4 /* RuntimeDemo */ = { 138 | isa = PBXNativeTarget; 139 | buildConfigurationList = 1A04A29E1B4927E5003DE2A4 /* Build configuration list for PBXNativeTarget "RuntimeDemo" */; 140 | buildPhases = ( 141 | 1A04A2781B4927E4003DE2A4 /* Sources */, 142 | 1A04A2791B4927E4003DE2A4 /* Frameworks */, 143 | 1A04A27A1B4927E4003DE2A4 /* Resources */, 144 | ); 145 | buildRules = ( 146 | ); 147 | dependencies = ( 148 | ); 149 | name = RuntimeDemo; 150 | productName = RuntimeDemo; 151 | productReference = 1A04A27C1B4927E4003DE2A4 /* RuntimeDemo.app */; 152 | productType = "com.apple.product-type.application"; 153 | }; 154 | 1A04A2941B4927E5003DE2A4 /* RuntimeDemoTests */ = { 155 | isa = PBXNativeTarget; 156 | buildConfigurationList = 1A04A2A11B4927E5003DE2A4 /* Build configuration list for PBXNativeTarget "RuntimeDemoTests" */; 157 | buildPhases = ( 158 | 1A04A2911B4927E5003DE2A4 /* Sources */, 159 | 1A04A2921B4927E5003DE2A4 /* Frameworks */, 160 | 1A04A2931B4927E5003DE2A4 /* Resources */, 161 | ); 162 | buildRules = ( 163 | ); 164 | dependencies = ( 165 | 1A04A2971B4927E5003DE2A4 /* PBXTargetDependency */, 166 | ); 167 | name = RuntimeDemoTests; 168 | productName = RuntimeDemoTests; 169 | productReference = 1A04A2951B4927E5003DE2A4 /* RuntimeDemoTests.xctest */; 170 | productType = "com.apple.product-type.bundle.unit-test"; 171 | }; 172 | /* End PBXNativeTarget section */ 173 | 174 | /* Begin PBXProject section */ 175 | 1A04A2741B4927E4003DE2A4 /* Project object */ = { 176 | isa = PBXProject; 177 | attributes = { 178 | LastUpgradeCheck = 0700; 179 | ORGANIZATIONNAME = "Sam Lau"; 180 | TargetAttributes = { 181 | 1A04A27B1B4927E4003DE2A4 = { 182 | CreatedOnToolsVersion = 7.0; 183 | }; 184 | 1A04A2941B4927E5003DE2A4 = { 185 | CreatedOnToolsVersion = 7.0; 186 | TestTargetID = 1A04A27B1B4927E4003DE2A4; 187 | }; 188 | }; 189 | }; 190 | buildConfigurationList = 1A04A2771B4927E4003DE2A4 /* Build configuration list for PBXProject "RuntimeDemo" */; 191 | compatibilityVersion = "Xcode 3.2"; 192 | developmentRegion = English; 193 | hasScannedForEncodings = 0; 194 | knownRegions = ( 195 | en, 196 | Base, 197 | ); 198 | mainGroup = 1A04A2731B4927E4003DE2A4; 199 | productRefGroup = 1A04A27D1B4927E4003DE2A4 /* Products */; 200 | projectDirPath = ""; 201 | projectRoot = ""; 202 | targets = ( 203 | 1A04A27B1B4927E4003DE2A4 /* RuntimeDemo */, 204 | 1A04A2941B4927E5003DE2A4 /* RuntimeDemoTests */, 205 | ); 206 | }; 207 | /* End PBXProject section */ 208 | 209 | /* Begin PBXResourcesBuildPhase section */ 210 | 1A04A27A1B4927E4003DE2A4 /* Resources */ = { 211 | isa = PBXResourcesBuildPhase; 212 | buildActionMask = 2147483647; 213 | files = ( 214 | 1A04A28F1B4927E4003DE2A4 /* LaunchScreen.storyboard in Resources */, 215 | 1A04A28C1B4927E4003DE2A4 /* Assets.xcassets in Resources */, 216 | 1A04A28A1B4927E4003DE2A4 /* Main.storyboard in Resources */, 217 | ); 218 | runOnlyForDeploymentPostprocessing = 0; 219 | }; 220 | 1A04A2931B4927E5003DE2A4 /* Resources */ = { 221 | isa = PBXResourcesBuildPhase; 222 | buildActionMask = 2147483647; 223 | files = ( 224 | ); 225 | runOnlyForDeploymentPostprocessing = 0; 226 | }; 227 | /* End PBXResourcesBuildPhase section */ 228 | 229 | /* Begin PBXSourcesBuildPhase section */ 230 | 1A04A2781B4927E4003DE2A4 /* Sources */ = { 231 | isa = PBXSourcesBuildPhase; 232 | buildActionMask = 2147483647; 233 | files = ( 234 | 1AF7BEE91B49524E003A0216 /* NSObject+AssociatedObject.m in Sources */, 235 | 1AF7BEEC1B495D8B003A0216 /* UIViewController+Logging.m in Sources */, 236 | 1A04A2871B4927E4003DE2A4 /* ViewController.m in Sources */, 237 | 1A04A2A61B492816003DE2A4 /* Message.m in Sources */, 238 | 1AADFBD21B49306900E4B5C8 /* MessageForwarding.m in Sources */, 239 | 1A04A2841B4927E4003DE2A4 /* AppDelegate.m in Sources */, 240 | 1A04A2811B4927E4003DE2A4 /* main.m in Sources */, 241 | ); 242 | runOnlyForDeploymentPostprocessing = 0; 243 | }; 244 | 1A04A2911B4927E5003DE2A4 /* Sources */ = { 245 | isa = PBXSourcesBuildPhase; 246 | buildActionMask = 2147483647; 247 | files = ( 248 | 1A04A29A1B4927E5003DE2A4 /* RuntimeDemoTests.m in Sources */, 249 | ); 250 | runOnlyForDeploymentPostprocessing = 0; 251 | }; 252 | /* End PBXSourcesBuildPhase section */ 253 | 254 | /* Begin PBXTargetDependency section */ 255 | 1A04A2971B4927E5003DE2A4 /* PBXTargetDependency */ = { 256 | isa = PBXTargetDependency; 257 | target = 1A04A27B1B4927E4003DE2A4 /* RuntimeDemo */; 258 | targetProxy = 1A04A2961B4927E5003DE2A4 /* PBXContainerItemProxy */; 259 | }; 260 | /* End PBXTargetDependency section */ 261 | 262 | /* Begin PBXVariantGroup section */ 263 | 1A04A2881B4927E4003DE2A4 /* Main.storyboard */ = { 264 | isa = PBXVariantGroup; 265 | children = ( 266 | 1A04A2891B4927E4003DE2A4 /* Base */, 267 | ); 268 | name = Main.storyboard; 269 | sourceTree = ""; 270 | }; 271 | 1A04A28D1B4927E4003DE2A4 /* LaunchScreen.storyboard */ = { 272 | isa = PBXVariantGroup; 273 | children = ( 274 | 1A04A28E1B4927E4003DE2A4 /* Base */, 275 | ); 276 | name = LaunchScreen.storyboard; 277 | sourceTree = ""; 278 | }; 279 | /* End PBXVariantGroup section */ 280 | 281 | /* Begin XCBuildConfiguration section */ 282 | 1A04A29C1B4927E5003DE2A4 /* Debug */ = { 283 | isa = XCBuildConfiguration; 284 | buildSettings = { 285 | ALWAYS_SEARCH_USER_PATHS = NO; 286 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 287 | CLANG_CXX_LIBRARY = "libc++"; 288 | CLANG_ENABLE_MODULES = YES; 289 | CLANG_ENABLE_OBJC_ARC = YES; 290 | CLANG_WARN_BOOL_CONVERSION = YES; 291 | CLANG_WARN_CONSTANT_CONVERSION = YES; 292 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 293 | CLANG_WARN_EMPTY_BODY = YES; 294 | CLANG_WARN_ENUM_CONVERSION = YES; 295 | CLANG_WARN_INT_CONVERSION = YES; 296 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 297 | CLANG_WARN_UNREACHABLE_CODE = YES; 298 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 299 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 300 | COPY_PHASE_STRIP = NO; 301 | DEBUG_INFORMATION_FORMAT = dwarf; 302 | ENABLE_STRICT_OBJC_MSGSEND = YES; 303 | ENABLE_TESTABILITY = YES; 304 | GCC_C_LANGUAGE_STANDARD = gnu99; 305 | GCC_DYNAMIC_NO_PIC = NO; 306 | GCC_NO_COMMON_BLOCKS = YES; 307 | GCC_OPTIMIZATION_LEVEL = 0; 308 | GCC_PREPROCESSOR_DEFINITIONS = ( 309 | "DEBUG=1", 310 | "$(inherited)", 311 | ); 312 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 313 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 314 | GCC_WARN_UNDECLARED_SELECTOR = YES; 315 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 316 | GCC_WARN_UNUSED_FUNCTION = YES; 317 | GCC_WARN_UNUSED_VARIABLE = YES; 318 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 319 | MTL_ENABLE_DEBUG_INFO = YES; 320 | ONLY_ACTIVE_ARCH = YES; 321 | SDKROOT = iphoneos; 322 | TARGETED_DEVICE_FAMILY = "1,2"; 323 | }; 324 | name = Debug; 325 | }; 326 | 1A04A29D1B4927E5003DE2A4 /* Release */ = { 327 | isa = XCBuildConfiguration; 328 | buildSettings = { 329 | ALWAYS_SEARCH_USER_PATHS = NO; 330 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 331 | CLANG_CXX_LIBRARY = "libc++"; 332 | CLANG_ENABLE_MODULES = YES; 333 | CLANG_ENABLE_OBJC_ARC = YES; 334 | CLANG_WARN_BOOL_CONVERSION = YES; 335 | CLANG_WARN_CONSTANT_CONVERSION = YES; 336 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 337 | CLANG_WARN_EMPTY_BODY = YES; 338 | CLANG_WARN_ENUM_CONVERSION = YES; 339 | CLANG_WARN_INT_CONVERSION = YES; 340 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 341 | CLANG_WARN_UNREACHABLE_CODE = YES; 342 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 343 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 344 | COPY_PHASE_STRIP = NO; 345 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 346 | ENABLE_NS_ASSERTIONS = NO; 347 | ENABLE_STRICT_OBJC_MSGSEND = YES; 348 | GCC_C_LANGUAGE_STANDARD = gnu99; 349 | GCC_NO_COMMON_BLOCKS = YES; 350 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 351 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 352 | GCC_WARN_UNDECLARED_SELECTOR = YES; 353 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 354 | GCC_WARN_UNUSED_FUNCTION = YES; 355 | GCC_WARN_UNUSED_VARIABLE = YES; 356 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 357 | MTL_ENABLE_DEBUG_INFO = NO; 358 | SDKROOT = iphoneos; 359 | TARGETED_DEVICE_FAMILY = "1,2"; 360 | VALIDATE_PRODUCT = YES; 361 | }; 362 | name = Release; 363 | }; 364 | 1A04A29F1B4927E5003DE2A4 /* Debug */ = { 365 | isa = XCBuildConfiguration; 366 | buildSettings = { 367 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 368 | INFOPLIST_FILE = RuntimeDemo/Info.plist; 369 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 370 | PRODUCT_BUNDLE_IDENTIFIER = com.samlaudev.RuntimeDemo; 371 | PRODUCT_NAME = "$(TARGET_NAME)"; 372 | }; 373 | name = Debug; 374 | }; 375 | 1A04A2A01B4927E5003DE2A4 /* Release */ = { 376 | isa = XCBuildConfiguration; 377 | buildSettings = { 378 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 379 | INFOPLIST_FILE = RuntimeDemo/Info.plist; 380 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 381 | PRODUCT_BUNDLE_IDENTIFIER = com.samlaudev.RuntimeDemo; 382 | PRODUCT_NAME = "$(TARGET_NAME)"; 383 | }; 384 | name = Release; 385 | }; 386 | 1A04A2A21B4927E5003DE2A4 /* Debug */ = { 387 | isa = XCBuildConfiguration; 388 | buildSettings = { 389 | BUNDLE_LOADER = "$(TEST_HOST)"; 390 | INFOPLIST_FILE = RuntimeDemoTests/Info.plist; 391 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 392 | PRODUCT_BUNDLE_IDENTIFIER = com.samlaudev.RuntimeDemoTests; 393 | PRODUCT_NAME = "$(TARGET_NAME)"; 394 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RuntimeDemo.app/RuntimeDemo"; 395 | }; 396 | name = Debug; 397 | }; 398 | 1A04A2A31B4927E5003DE2A4 /* Release */ = { 399 | isa = XCBuildConfiguration; 400 | buildSettings = { 401 | BUNDLE_LOADER = "$(TEST_HOST)"; 402 | INFOPLIST_FILE = RuntimeDemoTests/Info.plist; 403 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 404 | PRODUCT_BUNDLE_IDENTIFIER = com.samlaudev.RuntimeDemoTests; 405 | PRODUCT_NAME = "$(TARGET_NAME)"; 406 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RuntimeDemo.app/RuntimeDemo"; 407 | }; 408 | name = Release; 409 | }; 410 | /* End XCBuildConfiguration section */ 411 | 412 | /* Begin XCConfigurationList section */ 413 | 1A04A2771B4927E4003DE2A4 /* Build configuration list for PBXProject "RuntimeDemo" */ = { 414 | isa = XCConfigurationList; 415 | buildConfigurations = ( 416 | 1A04A29C1B4927E5003DE2A4 /* Debug */, 417 | 1A04A29D1B4927E5003DE2A4 /* Release */, 418 | ); 419 | defaultConfigurationIsVisible = 0; 420 | defaultConfigurationName = Release; 421 | }; 422 | 1A04A29E1B4927E5003DE2A4 /* Build configuration list for PBXNativeTarget "RuntimeDemo" */ = { 423 | isa = XCConfigurationList; 424 | buildConfigurations = ( 425 | 1A04A29F1B4927E5003DE2A4 /* Debug */, 426 | 1A04A2A01B4927E5003DE2A4 /* Release */, 427 | ); 428 | defaultConfigurationIsVisible = 0; 429 | defaultConfigurationName = Release; 430 | }; 431 | 1A04A2A11B4927E5003DE2A4 /* Build configuration list for PBXNativeTarget "RuntimeDemoTests" */ = { 432 | isa = XCConfigurationList; 433 | buildConfigurations = ( 434 | 1A04A2A21B4927E5003DE2A4 /* Debug */, 435 | 1A04A2A31B4927E5003DE2A4 /* Release */, 436 | ); 437 | defaultConfigurationIsVisible = 0; 438 | defaultConfigurationName = Release; 439 | }; 440 | /* End XCConfigurationList section */ 441 | }; 442 | rootObject = 1A04A2741B4927E4003DE2A4 /* Project object */; 443 | } 444 | -------------------------------------------------------------------------------- /RuntimeDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /RuntimeDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // RuntimeDemo 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /RuntimeDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // RuntimeDemo 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /RuntimeDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /RuntimeDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 26 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /RuntimeDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /RuntimeDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /RuntimeDemo/Message.h: -------------------------------------------------------------------------------- 1 | // 2 | // Message.h 3 | // RuntimeDemo 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface Message : NSObject 12 | 13 | - (void)sendMessage:(NSString *)word; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /RuntimeDemo/Message.m: -------------------------------------------------------------------------------- 1 | // 2 | // Message.m 3 | // RuntimeDemo 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import "Message.h" 10 | #import "MessageForwarding.h" 11 | #import 12 | 13 | @implementation Message 14 | 15 | //- (void)sendMessage:(NSString *)word 16 | //{ 17 | // NSLog(@"normal way : send message = %@", word); 18 | //} 19 | 20 | #pragma mark - Method Resolution 21 | /// override resolveInstanceMethod or resolveClassMethod for changing sendMessage method implementation 22 | //+ (BOOL)resolveInstanceMethod:(SEL)sel 23 | //{ 24 | // if (sel == @selector(sendMessage:)) { 25 | // class_addMethod([self class], sel, imp_implementationWithBlock(^(id self, NSString *word) { 26 | // NSLog(@"method resolution way : send message = %@", word); 27 | // }), "v@*"); 28 | // } 29 | // 30 | // return YES; 31 | //} 32 | 33 | #pragma mark - Fast Forwarding 34 | //- (id)forwardingTargetForSelector:(SEL)aSelector 35 | //{ 36 | // if (aSelector == @selector(sendMessage:)) { 37 | // return [MessageForwarding new]; 38 | // } 39 | // 40 | // return nil; 41 | //} 42 | 43 | 44 | #pragma mark - Normal Forwarding 45 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector 46 | { 47 | NSMethodSignature *methodSignature = [super methodSignatureForSelector:aSelector]; 48 | 49 | if (!methodSignature) { 50 | methodSignature = [NSMethodSignature signatureWithObjCTypes:"v@:*"]; 51 | } 52 | 53 | return methodSignature; 54 | } 55 | 56 | - (void)forwardInvocation:(NSInvocation *)anInvocation 57 | { 58 | MessageForwarding *messageForwarding = [MessageForwarding new]; 59 | 60 | if ([messageForwarding respondsToSelector:anInvocation.selector]) { 61 | [anInvocation invokeWithTarget:messageForwarding]; 62 | } 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /RuntimeDemo/MessageForwarding.h: -------------------------------------------------------------------------------- 1 | // 2 | // MessageForwarding.h 3 | // RuntimeDemo 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MessageForwarding : NSObject 12 | 13 | - (void)sendMessage:(NSString *)word; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /RuntimeDemo/MessageForwarding.m: -------------------------------------------------------------------------------- 1 | // 2 | // MessageForwarding.m 3 | // RuntimeDemo 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import "MessageForwarding.h" 10 | 11 | @implementation MessageForwarding 12 | 13 | - (void)sendMessage:(NSString *)word 14 | { 15 | NSLog(@"fast forwarding way : send message = %@", word); 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /RuntimeDemo/MessageForwarding~.h: -------------------------------------------------------------------------------- 1 | // 2 | // MessageForwarding.h 3 | // RuntimeDemo 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MessageForwarding : NSObject 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /RuntimeDemo/NSObject+AssociatedObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+AssociatedObject.h 3 | // RuntimeDemo 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSObject (AssociatedObject) 12 | 13 | @property (strong, nonatomic) id associatedObject; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /RuntimeDemo/NSObject+AssociatedObject.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+AssociatedObject.m 3 | // RuntimeDemo 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import "NSObject+AssociatedObject.h" 10 | #import 11 | 12 | @implementation NSObject (AssociatedObject) 13 | 14 | - (void)setAssociatedObject:(id)associatedObject 15 | { 16 | objc_setAssociatedObject(self, @selector(associatedObject), associatedObject, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 17 | } 18 | 19 | - (id)associatedObject 20 | { 21 | return objc_getAssociatedObject(self, _cmd); 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /RuntimeDemo/UIViewController+Logging.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+Logging.h 3 | // RuntimeDemo 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIViewController (Logging) 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /RuntimeDemo/UIViewController+Logging.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+Logging.m 3 | // RuntimeDemo 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import "UIViewController+Logging.h" 10 | #import 11 | 12 | @implementation UIViewController (Logging) 13 | 14 | + (void)load 15 | { 16 | swizzleMethod([self class], @selector(viewDidAppear:), @selector(swizzled_viewDidAppear:)); 17 | } 18 | 19 | - (void)swizzled_viewDidAppear:(BOOL)animated 20 | { 21 | // call original implementation 22 | [self swizzled_viewDidAppear:animated]; 23 | 24 | // Logging 25 | NSLog(@"%@", NSStringFromClass([self class])); 26 | } 27 | 28 | void swizzleMethod(Class class, SEL originalSelector, SEL swizzledSelector) 29 | { 30 | // the method might not exist in the class, but in its superclass 31 | Method originalMethod = class_getInstanceMethod(class, originalSelector); 32 | Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); 33 | 34 | // class_addMethod will fail if original method already exists 35 | BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); 36 | 37 | // the method doesn’t exist and we just added one 38 | if (didAddMethod) { 39 | class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); 40 | } 41 | else { 42 | method_exchangeImplementations(originalMethod, swizzledMethod); 43 | } 44 | 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /RuntimeDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // RuntimeDemo 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /RuntimeDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // RuntimeDemo 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "Message.h" 11 | #import "NSObject+AssociatedObject.h" 12 | 13 | @interface ViewController () 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | 22 | Message *message = [Message new]; 23 | [message sendMessage:@"Sam Lau"]; 24 | 25 | NSObject *objc = [NSObject new]; 26 | objc.associatedObject = @"Extend Category"; 27 | NSLog(@"associatedObject is = %@", objc.associatedObject); 28 | } 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /RuntimeDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // RuntimeDemo 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /RuntimeDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /RuntimeDemoTests/RuntimeDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // RuntimeDemoTests.m 3 | // RuntimeDemoTests 4 | // 5 | // Created by Sam Lau on 7/5/15. 6 | // Copyright © 2015 Sam Lau. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface RuntimeDemoTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation RuntimeDemoTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | --------------------------------------------------------------------------------