سؤال

I have a UIButton which I've set the accessibilityLabel on. Why can't the console find the accessibility label property when I try to print it using dot notation?

(lldb) po self.closeButton.accessibilityLabel
error: property 'accessibilityLabel' not found on object of type 'UIButton *'
error: 1 errors parsing expression
(lldb) po [self.closeButton accessibilityLabel]
topsecretlabel
هل كانت مفيدة؟

المحلول

accessibilityLabel is not a property of UIButton. It is a method defined by the informal UIAccessibility protocol that UIButton happens to respond to. lldb tends to be more strict about these things than clang is, and it is not strictly legal to refer to a non-property by dot-notation.

The fact that it's an informal protocol actually makes things much harder on lldb. You cannot easily determine that UIButton implements the protocol (it's technically an extension of NSObject). We don't use informal protocols as much anymore for that reason.

نصائح أخرى

One of the things you can specify as part of the declaration of ObjC properties is setters and getters that don't follow the normal naming convention. So without knowing the details of the property declaration, lldb doesn't know how to turn the dot notation into the correct method call. If it has debug information, it can do this job. But we try not to guess about this sort of thing in the debugger. So if we don't have debug info, you have to tell us what the setter is (by manually converting the . notation to the correct method call.)

Anyway, you do have access to the header file that declares accessibilityLabel property so this still should work correctly. Sadly, there is a bug in clang that it doesn't emit debug information for properties declared in categories on classes. As it turns out, accessibilityLabel is defined in the UIAccessibility category on NSObject. So it gets no debug information. So you can't use dot notation on it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top