Array handling in document properties

40 views
Skip to first unread message

Alan McKean

unread,
Feb 17, 2014, 9:28:32 PM2/17/14
to mobile-c...@googlegroups.com
Why would this happen in a model? I'm breaking inside of a method that calculates total charges, based on the array of dictionaries where each has a billing code and an associated charge. BTW, the patient name is fictitious.
```

(lldb) po self.document.properties

{

    "_id" = 8387530937fe51a59365e882fe2b8ff9;

    "_rev" = "2-d7f14c03e7226c400e1f56034f1d91c1";

    authorizationNumber = "";

    charges =     (

                {

            charge = 55;

            code = 99211;

        },

                {

            charge = 150;

            code = 90836;

        }

    );

    correctedClaim = 0;

    dateOfService = 1380524400;

    dateSubmitted = "1391384939.515375";

    insured = "";

    insurerId = edc7d4fee17ca1792d5ecf9254e88b0a;

    insurerName = "Kaiser Foundation Health Plan of the Northwest";

    patientId = 05acac91de863a80ffb189a3cf7b6612;

    patientName = "AISHA T. HOFSTADTER";

    policyNumber = 12345678M;

    sessionId = 8387530937fe51a59365e882fe12e73b;

    status = unpaid;

    type = claim;

}

 

(lldb) po self.charges

 nil

```

I have a property in my model:
```

@property (nonatomic, strong) NSArray * charges;

```
I need to iterate the array of charges to calculate the total charges but I keep getting nil from self.charges in my totalCharges method.

Jens Alfke

unread,
Feb 17, 2014, 9:35:35 PM2/17/14
to mobile-c...@googlegroups.com

On Feb 17, 2014, at 6:28 PM, Alan McKean <alanm...@me.com> wrote:

(lldb) po self.charges

 nil

```

I have a property in my model:
```

@property (nonatomic, strong) NSArray * charges;


I'll bet you forgot to declare the property as @dynamic in the implementation.
If you don't, Clang will decide to synthesize it for you, so you end up with it being nil by default (and never being saved to the document even if you set it.)

To avoid this, there's a warning you can turn on about "implicit auto-synthesize" or something like that. I recommend enabling it.

—Jens

Alan McKean

unread,
Feb 17, 2014, 9:55:51 PM2/17/14
to mobile-c...@googlegroups.com
Duh! Thanks. That did it.
Reply all
Reply to author
Forward
0 new messages