Private なメソッド、プロパティ、インスタンス変数を調べる
クラスの Private なメソッド、プロパティ、インスタンス変数を調べるには Objective-C の Runtime API を使う。
メソッドは Method
, プロパティは objc_property_t
, インスタンス変数は Ivar
型で取得できる。
#import <objc/runtime.h>
で Runtime API を import してそれぞれ以下のように実装する。
これを使って例えば NSObject
について調べる場合、以下のようにする。
Class cls = [NSObject class];
PrintMethodList(cls);
PrintPropertyList(cls);
PrintIvarList(cls);
出力結果は以下
ちょっとメソッドのリストが長いのでメソッド一覧は最後に記載。
見てみると Private なものでもアンダーバーが付いてないものもあれば、アンダーバーが3つも付いているものもあったりする。
他には CA_ みたいに Prefix+アンダーバー形式のものもあったりしておもしろい。
プロパティの出力結果
// Property List of NSObject accessibilityElements accessibilityCustomActions isAccessibilityElement accessibilityLabel accessibilityHint accessibilityValue accessibilityTraits accessibilityFrame accessibilityPath accessibilityActivationPoint accessibilityLanguage accessibilityElementsHidden accessibilityViewIsModal shouldGroupAccessibilityChildren accessibilityNavigationStyle traitStorageList autoContentAccessingProxy classForKeyedArchiver observationInfo hash superclass description debugDescription
インスタンス変数の出力結果
// Ivar List of NSObject isa
メソッドの出力結果
// Method List of UIView className _NSItemProviderTypeCoercion_coercedUIImageValueFromNSURLValue:error: _NSItemProviderTypeCoercion_coercedUIImageValueFromNSDataValue:error: defaultAccessibilityTraits isAccessibilityElementByDefault isElementAccessibilityExposedToInterfaceBuilder _accessibilityFinalize accessibilitySetIdentification: accessibilityElements setAccessibilityElements: accessibilityElementCount accessibilityElementAtIndex: indexOfAccessibilityElement: accessibilityIncrement accessibilityDecrement accessibilityScroll: accessibilityPerformEscape accessibilityPerformMagicTap accessibilityActivate setAccessibilityCustomActions: accessibilityCustomActions accessibilityElementDidBecomeFocused accessibilityElementDidLoseFocus accessibilityElementIsFocused accessibilityIdentifier accessibilityFrame storedAccessibilityViewIsModal storedAccessibilityElementsHidden storedShouldGroupAccessibilityChildren storedAccessibilityNavigationStyle accessibilityHint accessibilityActivationPoint accessibilityTraits accessibilityLanguage accessibilityPath accessibilityViewIsModal accessibilityElementsHidden shouldGroupAccessibilityChildren accessibilityNavigationStyle storedAccessibilityTraits storedIsAccessibilityElement storedAccessibilityFrame storedAccessibilityActivationPoint setAccessibilityElementsHidden: setAccessibilityViewIsModal: setAccessibilityHint: setAccessibilityFrame: setAccessibilityPath: setAccessibilityActivationPoint: setAccessibilityTraits: setIsAccessibilityElement: setAccessibilityContainer: setAccessibilityLanguage: setAccessibilityIdentifier: setShouldGroupAccessibilityChildren: setAccessibilityNavigationStyle: setAccessibilityLabel: accessibilityValue setAccessibilityValue: accessibilityLabel isAccessibilityElement accessibilityContainer awakeFromNib prepareForInterfaceBuilder _connectInterfaceBuilderEventConnection: _applyTraitStorageRecordsForTraitCollection: _traitStorageList _setTraitStorageList: __ivarDescriptionForClass: __methodDescriptionForClass: _ivarDescription _methodDescription _shortMethodDescription _webkit_invokeOnMainThread postNotificationWithDescription: okToNotifyFromThisThread fromNotifySafeThreadPerformSelector:withObject: allowSafePerformSelector disallowSafePerformSelector fromNotifySafeThreadPostNotificationName:object:userInfo: fromMainThreadPostNotificationName:object:userInfo: releaseOnMainThread sbs_isPlistableType encodeWithCAMLWriter: CAMLTypeForKey: CAMLType CA_addValue:multipliedBy: CA_interpolateValue:byFraction: CA_roundToIntegerFromValue: CA_distanceToValue: CA_interpolateValues:::interpolator: CA_copyRenderValue CA_prepareRenderValue bs_performSynchronously:timeout: bs_isPlistableType pep_onMainThread pep_onThread: pep_onThread:immediateForMatchingThread: pep_onOperationQueue:priority: pep_onMainThreadIfNecessary pep_onDetachedThread pep_afterDelay: pep_onOperationQueue: pep_getInvocation: __im_afterDelay: __im_afterDelay:modes: __im_onThread: __im_onThread:immediateForMatchingThread: __im_onMainThread __im_onMainThreadIfNecessary __im_onDetachedThread __im_getInvocation: performSelector:withObject:afterDelay:ignoreMenuTracking: isNull classForPortCoder replacementObjectForPortCoder: _conformsToProtocolNamed: methodDescriptionForSelector: _localClassNameForClass performSelector:onThread:withObject:waitUntilDone:modes: performSelectorOnMainThread:withObject:waitUntilDone: performSelectorInBackground:withObject: performSelectorOnMainThread:withObject:waitUntilDone:modes: performSelector:onThread:withObject:waitUntilDone: performSelector:withObject:afterDelay:inModes: performSelector:withObject:afterDelay: performSelector:object:afterDelay: autoContentAccessingProxy classForCoder replacementObjectForCoder: awakeAfterUsingCoder: _allowsDirectEncoding implementsSelector: classForKeyedArchiver replacementObjectForKeyedArchiver: _implicitObservationInfo _changeValueForKey:key:key:usingBlock: _notifyObserversForKeyPath:change: _changeValueForKey:usingBlock: _willChangeValuesForKeys: _didChangeValuesForKeys: observationInfo setObservationInfo: willChange:valuesAtIndexes:forKey: didChange:valuesAtIndexes:forKey: willChangeValueForKey:withSetMutation:usingObjects: didChangeValueForKey:withSetMutation:usingObjects: willChangeValueForKey: didChangeValueForKey: _addObserver:forProperty:options:context: _removeObserver:forProperty: addObserver:forKeyPath:options:context: removeObserver:forKeyPath: removeObserver:forKeyPath:context: observeValueForKeyPath:ofObject:change:context: _isKVOA valueForUndefinedKey: setValue:forUndefinedKey: setNilValueForKey: setValue:forKeyPath: validateValue:forKeyPath:error: validateValue:forKey:error: mutableArrayValueForKeyPath: mutableArrayValueForKey: mutableOrderedSetValueForKeyPath: mutableOrderedSetValueForKey: mutableSetValueForKeyPath: mutableSetValueForKey: setValue:forKey: valueForKey: valueForKeyPath: setValuesForKeysWithDictionary: dictionaryWithValuesForKeys: replacementObjectForArchiver: classForArchiver _cfTypeID isNSValue__ isNSString__ isNSNumber__ isNSArray__ isNSDictionary__ isNSData__ isNSDate__ isNSOrderedSet__ isNSSet__ isNSTimeZone__ doesNotRecognizeSelector: description methodSignatureForSelector: __dealloc_zombie __retain_OA __release_OA __autorelease_OA ___tryRetain_OA _copyDescription zone doesNotRecognizeSelector: description retain release autorelease retainCount dealloc copy finalize forwardInvocation: _tryRetain _isDeallocating retainWeakReference allowsWeakReference isKindOfClass: mutableCopy hash isEqual: respondsToSelector: self performSelector: performSelector:withObject: conformsToProtocol: methodSignatureForSelector: forwardingTargetForSelector: methodForSelector: performSelector:withObject:withObject: isProxy isMemberOfClass: superclass class debugDescription init isFault