iOS Question iOS Map Collections (Read Only)

fbritop

Active Member
Licensed User
Longtime User
Erel,
Is it possible in B4I to attach an imageview to a map key?

I have done it in Android but in iOS there is no chance to retrieve this image after from the map.

Is there any special treament to attach an imageview to a map?. Same thing happends when I put a label. After putting any of these items, if I log the map it outputs only numeric or string values:

B4X:
(read only map) {
    idProducto = 1302;
    isActive = 1;
    isDelete = 0;
    isDiferido = 0;
    isNew = 0;
    isOffer = 0;
    precio = 36900;
    precioFormat = "$ 36.900";
    producto = "Nutra Nuggets Large Breed Puppy";
    unidad = "SACO 15 KG";
}
 

fbritop

Active Member
Licensed User
Longtime User
Erel,
I figured out what happens with this problem.

It seems than in B4I, when a map comes from a JSON Object it turns out automatically to a Read Only Map:

JSON:
{"favoritos":[{"item1", "item2", "item3"}]}

.....
B4X:
Dim map1 As Map = JSONP.NextObject
favoritos = map1.get("favoritos")
Dim m as Map
For i = 0 To favoritos.Size - 1
    m = favoritos.Get(i)
    log(m)
next

This code execution, in the log will bring a (read only map), which I cannot "PUT" any other item into it. This disables any chance that from a CustomListView to retrieve any object that’s inside (which is an excellent method to reference any views created dynamically).

After some tests, I did a small function to transform a Read Only Map to an NSMapTable

B4X:
Sub map2Map(m As Map) As Map
    Dim m2 As Map
    m2.Initialize
    For Each key As String In m.keys
        m2.put(key,m.Get(key))
    Next
    Return m2
End Sub

Dim mProcess as Map=map2Map(m)
log(mProcess)

Now if we log the mProcess Map after passing it through map2map function, now it contains a writeable Map

Hope it helps any lost souls with this same trouble.
FBP
 
  • Like
Reactions: TnP
Upvote 0
Top