objective-carrayscore-datansmutablearraynsarray

__NSSingleObjectArrayI in Coredata


I am working with Coredata. i have an relation with the entity when i fetch my relation it gives the NSSet and i Convert this to NSMutableArray with AllObjects. The issue it gives me __NSSingleObjectArrayI instead of NSMutableArray. Can any one please help me on this. Thanks

Tired Code :-

NSSet *arrPayment = [[[dictPaymentData allValues] valueForKey:@"paymentToInvoice"] valueForKey:@"invoiceToPeople"];
          NSMutableArray *arrData = [NSMutableArray arrayWithArray:[arrPayment allObjects]];

This is my __NSSingleObjectArrayI Code :-

<__NSArrayM 0x6000018464f0>(
<__NSSingleObjectArrayI 0x600000a8bdd0>(
{(
    <People: 0x600002b44370> (entity: People; id: 0x91782a4d7073f8e8 <x-coredata://0785667E-51C4-4C34-B696-C4374F6315D4/People/p630> ; data: {
    archiveStatus = 0;
    defaultTerms = 30;
    email = nil;
    extra1 = nil;
    extra2 = nil;
    extra3 = nil;
    faxNo = nil;
    firstName = nil;
    from = nil;
    fromid = 0;
    homeNo = nil;
    internalNotes = nil;
    lastName = nil;
    mobileNO = nil;
    modificationDate = "2019-01-17 11:58:50 +0000";
    organization = Yogesh;
    peopleId = 0;
    "sa_City" = nil;
    "sa_Country" = nil;
    "sa_State" = nil;
    "sa_Street1" = nil;
    "sa_Street2" = nil;
    "sa_Zip" = nil;
    selectedCurrency = "en_US";
    signature = nil;
    sortingString = nil;
    status = Cactive;
    syncID = nil;
    uniqueIdentifier = "6A819F69-DCB0-4B6C-BE60-03151B23541D-3341-0000043F5397E622";
    userId = nil;
    vatNo = nil;
})
)}
)
)
,

Solution

  • Use mutableCopy by your array for correct type casting and escapes __NSSingleObjectArrayI

    // Two example of Incorrect cast to __NSSingleObjectArrayI
    NSMutableArray* contactsArr = (NSMutableArray*)[jsonDict valueForKey:@"users"];
    contactsArr = [NSMutableArray arrayWithArray:[jsonDict valueForKey:@"users"]];
    //Both result of init contactsArr will be __NSSingleObjectArrayI
    

    Use that

    //Correct Cast to NSMutableArray
    NSMutableArray* contactsArr = [[jsonDict valueForKey:@"users"] mutableCopy];