Inderpal Singh Inderpal Singh - 2 months ago 7
iOS Question

How to save fetched iCloud data objects into a single Array?

This is all my objects and i want to save all objects into single array.

**dataArray:**

<__NSArrayI 0x15e1a460>(
<__NSArrayM 0x15e244a0>(
<CKAsset: 0x15e69770; UUID=ED94A2F1-66C9-4D7C-B0E8-6A51EDBDDECE, arrayIndex=0, size=265849, path="/private~/Library/Caches/CloudKit/Assets/ED94A2F1-66C9-4D7C-B0E8-6A51EDBDDECE.01f8820d30f6147d76af04d3e84ccedc267da5f22d", signature=<01f8820d 30f6147d 76af04d3 e84ccedc 267da5f2 2d>, uploadRank=0>
)
,
<__NSArrayM 0x1706aac0>(
<CKAsset: 0x15ef1d90; UUID=46CA6A72-E1B4-4E03-AF8C-AEA557F62219, arrayIndex=0, size=49637, path="/private~/Library/Caches/CloudKit/Assets/46CA6A72-E1B4-4E03-AF8C-AEA557F62219.010c8944dcfd55b051c51c846092a61d4909708c97", signature=<010c8944 dcfd55b0 51c51c84 6092a61d 4909708c 97>, uploadRank=0>
)
,
<__NSArrayM 0x15e3f120>(
<CKAsset: 0x15e1ffc0; UUID=63018B1D-E340-4963-8BDC-8A2B5E108040, arrayIndex=0, size=102627, path="/private~/Library/Caches/CloudKit/Assets/63018B1D-E340-4963-8BDC-8A2B5E108040.0188b8d9b7cb6f914c2cd7fdb00b08aef3d1296ff0", signature=<0188b8d9 b7cb6f91 4c2cd7fd b00b08ae f3d1296f f0>, uploadRank=0>,

<CKAsset: 0x17057f00; UUID=96A26885-B0E2-4CCC-A571-07D94F22BB56, arrayIndex=1, size=88073, path="/private~/Library/Caches/CloudKit/Assets/96A26885-B0E2-4CCC-A571-07D94F22BB56.015bc1a8cc592f93343ad3baa7b5e92c1bd2c46099", signature=<015bc1a8 cc592f93 343ad3ba a7b5e92c 1bd2c460 99>, uploadRank=0>,

<CKAsset: 0x1706c5f0; UUID=E712BA16-4937-426C-88B4-5535B75F2507, arrayIndex=2, size=86948, path="/private~/Library/Caches/CloudKit/Assets/E712BA16-4937-426C-88B4-5535B75F2507.01a0f2f4bd2e4f92b6b0a530042db554f9904cb965", signature=<01a0f2f4 bd2e4f92 b6b0a530 042db554 f9904cb9 65>, uploadRank=0>
)
,
<__NSArrayM 0x15ecee30>(
<CKAsset: 0x15e3a980; UUID=66515C6E-0181-40C3-8A19-9BE4DBB3AFB5, arrayIndex=0, size=80674, path="/private~/Library/Caches/CloudKit/Assets/66515C6E-0181-40C3-8A19-9BE4DBB3AFB5.0187d802244e8b15b9a70e39755ce55433df6740cb", signature=<0187d802 244e8b15 b9a70e39 755ce554 33df6740 cb>, uploadRank=0>,

<CKAsset: 0x15ef3460; UUID=D80DC154-9278-4F46-9064-7888419C14D4, arrayIndex=1, size=29815, path="/private~/Library/Caches/CloudKit/Assets/D80DC154-9278-4F46-9064-7888419C14D4.012562c3defcf5833f065f305deb8bf83568147293", signature=<012562c3 defcf583 3f065f30 5deb8bf8 35681472 93>, uploadRank=0>
)
,
<__NSArrayM 0x15e3dec0>(
<CKAsset: 0x15e0c2c0; UUID=7357121B-18F6-4094-8844-19F79604FC88, arrayIndex=0, size=90252, path="/private~/Library/Caches/CloudKit/Assets/7357121B-18F6-4094-8844-19F79604FC88.01ee86884fc42ac4aa4ca519508e62e6b6306ad4fd", signature=<01ee8688 4fc42ac4 aa4ca519 508e62e6 b6306ad4 fd>, uploadRank=0>
)
)


I am using this loop for to get all objects and save into single Array:

for (int i = 0 ; i < dataArray.count; i++){
for (int j = 0 ; j<[[dataArray objectAtIndex:i] count]; j++) {
total addObject:[dataArray objectAtIndex:j]];
}
}

Answer

Using C-style iteration is not absolutely necessary, here's what you could do:

for(id object in dataArray) {
    for(id subobject in object) {
        [mutableArray addObject:subobject];
    }
}