Is there a way to log all the property values of an Objective-C instance

I was just wondering if there is a quick and easy way of printing out to the log all of the various values of the properties to my class for debugging purposes. Like I would like to know what the values of all of the BOOLs, floats, etc. are.

This question seems the have the answer to your question.


I got curious and made a catagory:

//Using Xcode 4.5.2 - iOS 6 - LLDB - Automatic Reference Counting

@interface NSObject (logProperties)
- (void) logProperties;

#import "NSObject+logProperties.h"
#import <objc/runtime.h>

@implementation NSObject (logProperties)

- (void) logProperties {

    NSLog(@"----------------------------------------------- Properties for object %@", self);

    @autoreleasepool {
        unsigned int numberOfProperties = 0;
        objc_property_t *propertyArray = class_copyPropertyList([self class], &numberOfProperties);
        for (NSUInteger i = 0; i < numberOfProperties; i++) {
            objc_property_t property = propertyArray[i];
            NSString *name = [[NSString alloc] initWithUTF8String:property_getName(property)];
            NSLog(@"Property %@ Value: %@", name, [self valueForKey:name]);


Include it in your class: #import "NSObject+logProperties.h"

and call [self logProperties]; to those properties!

Customize your Firebase Crashlytics crash reports, This guide describes how to customize your crash reports using the Firebase By default, Crashlytics automatically collects crash reports for all your app's users (you you pass to log() must conform to the CustomStringConvertible property. log() If you ever need to clear a user identifier after you set it, reset the value to a� In Objective-C, all objects are represented as pointers, and static initialization is not allowed. The simplest object is the type that id (objc_obj *) points to, which only has an isa pointer describing its class. Other types from C, like values and structs, are unchanged because they are not part of the object system.

The current answers just show how to do it for properties. If you want every instance variable printed out you could do something like the below.

- (void)logAllProperties {
    unsigned int count;
    Ivar *ivars = class_copyIvarList([self class], &count);
    for (unsigned int i = 0; i < count; i++) {
        Ivar ivar = ivars[i];

        const char *name = ivar_getName(ivar);
        const char *type = ivar_getTypeEncoding(ivar);
        ptrdiff_t offset = ivar_getOffset(ivar);

        if (strncmp(type, "i", 1) == 0) {
            int intValue = *(int*)((uintptr_t)self + offset);
            NSLog(@"%s = %i", name, intValue);
        } else if (strncmp(type, "f", 1) == 0) {
            float floatValue = *(float*)((uintptr_t)self + offset);
            NSLog(@"%s = %f", name, floatValue);
        } else if (strncmp(type, "@", 1) == 0) {
            id value = object_getIvar(self, ivar);
            NSLog(@"%s = %@", name, value);
        // And the rest for other type encodings

Although I wouldn't particularly suggest doing this in practice, but if it's for debug purposes then that's fine. You could implement this as a category on NSObject and keep it lying around for use when debugging. If completed for all type encodings then it could make for a very nice little method.

Object, Nearly all objects in JavaScript are instances of Object ; a typical object There isn't any method in an Object itself to delete its own properties (such as Object. assign(): Copies the values of all enumerable own properties from myFn 's body will contain 3 array-like elements corresponding to (a, b, c) . Declare in an instance variable as property provides the external class with access. Property Attributes. 1) Atomic: In objective c by default property attribute is atomic in atomic multiple threads are created for setting and getting the values for creating thread extra code will be generated and it leads to performance issue. 2) Non-atomic:

There are now these methods on NSObject :

@interface NSObject (Private)

In swift:


Thanks to this article

Public class fields, Both static and instance public fields are writable, enumerable, and configurable properties. As such, unlike their private counterparts, they participate in prototype static staticField = 'static field' } console.log(ClassWithStaticField. Getters and setters are special methods that bind to a class property and� Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

yes, one way would be to ask for all properties and then use KVC for example:

unsigned int cProperties = 0;
objc_property_t *props = class_copyPropertyList(self.class, &cProperties);
for(int i = 0; i < cProperties; i++) {
    const char *name = property_getName(props[i]);
    NSLog(@"%@=%@", name, [self valueForKey:name];

an alternate way is to go through all the methods of a class, get the return type, invoke and print it

17. Objects and Inheritance - Speaking JavaScript [Book], The value of a property can be any JavaScript value, including a function. Methods are it is invoked on. apply() for Constructors explains how to use apply() with constructors. for (var x in obj) console.log(x); objEnumTrue protoEnumTrue. Object.keys() That object becomes the prototype of all instances of C : > function� A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in Objective-C has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.

The quick and dirty would be to override debugDescription:

-(NSString*)debugDescription {
    NSString *str = [[NSString alloc] initWithFormat:@"My BOOL 1: %d, My Float: %f", self.myBool, self.myFoat];
    return str;

Of course, if your object is complex, this could be time consuming.

Working with Transactions, This chapter discusses the advantages of using transactions, how you define and You can assemble and inspect a given instance, view any property values for that (In this case, Business Transaction Management logs all messages for the B will have no ECID, and the messages for A and C will have different ECIDs. Objective-C properties offer a way to define the information that a class is intended to encapsulate. As you saw in Properties Control Access to an Object’s Values, property declarations are included in the interface for a class, like this:

Protocols — The Swift Programming Language (Swift 5.3), You define protocols in a very similar way to classes, structures, and enumerations: A protocol can require any conforming type to provide an instance property or For instance methods on value types (that is, structures and enumerations) only by classes that inherit from Objective-C classes or other @objc classes. In the same way that all living organisms share some basic “life” characteristics, some functionality is common across all objects in Objective-C. When an Objective-C object needs to work with an instance of another class, it is expected that the other class offers certain basic characteristics and behavior.

Objective-C, The following steps describe how to set up a build phase in Xcode to do this Remove all the Couchbase Lite 1.x dependencies (see the 1.x installation Therefore, to use replication with Couchbase Lite 2.x, the target Sync Gateway instance If the property doesn't exist in the document it will return the default value for� In Objective-C, you'd have to override property getter and set and initialize its value only if the underlying instance variable is nil. Red flag: You don't have to go too deep into the details of properties implementations and features in Swift and Objective-C but you have to know at least the basics of strong/weak/unowned referencing.

NSObject, The root class of most Objective-C class hierarchies, from which subclasses inherit a Returns a Boolean value that indicates whether instances of the receiver are capable of The keys for the to-one relationship properties of the receiver, if any. An informal protocol that provides a way to find out whether an assistive� So let’s see if there’s an easier way! Get Chair, Set Coding. If you’re familiar with other languages such as Java or C#, you’re probably familiar with the concepts of getters and setters. When you have an instance variable such as _sushiTypes, you often want another class to be able to access it.

  • @Tieme I like this kind of thing.. but I like it to look pretty, and be SUPER short, hence.. A concise category on NSObject to log all declared properties, pretty-like, using minimal SLOC. (Also, yours made my programs crash 🙉)
  • Of course this only works for objects, not primitive types like floats and bool. How would you go about to solve the problem with the format specifier in your NSLog that currently logs objects for properties and crashes on primitive types (%@)?
  • see the answer above by matt
  • only if you like typing ;) or if it is only for one object!
  • @Daij-Djan Hence the disclaimer.