Closed ibengeu closed 1 year ago
Do take a look @Kylmakalle
You're trying to change objects which were returned by the server. I don't know why you need it (since you can't return the same abject back to server to make changes) Instead, make a copy of object you need and do any related changes.
var customChatPositions: [ChatPosition] = chat.positions
for chatPosition in customChatPositions {
/* ... */
}
First of thanks for you time, and apologize for any noob questions or cases.
You're trying to change objects which were returned by the server
Not exactly, the response is stored in a dictionary(cache) of which i retrieve and potentially want to update
Instead, make a copy of object you need and do any related changes.
Agreed, worked with a similar structure but faced with the same issues of let constants. see an example below
case .updateChatTitle(let updateChat):
var chat = ChatHandler.getChat(chatId: updateChat.chatId)
chat?.title = updateChat.title // throws error here
break
// other cases with update
You're trying to change objects which were returned by the server
Not exactly
potentially want to update
So you are
response is stored in a dictionary(cache)
TDLib has its own cache, so whenever you will request a new chat object, it should return you a cached one. If you want to make sure that all the fields are up to date, use methods like openChat
to enforce the update mechanism.
If you're still not satisfied with this, you can create an extension or child class for objects you need to make changes and add additional fields through them. Structs are not final
.
Alright, although not clear - I would take a step back to think of the suggestions plus reason about the parser.
Because of immutable properties in struct's I made Custom<original name>
structs, where I had to update some data, like chat positions and ended with this for the moment:
struct CustomChat: Identifiable, Equatable {
let id = UUID()
var chat: Chat
var user: User
var positions: [ChatPosition]
var lastMessage: Message?
var draftMessage: DraftMessage?
}
Just create some func, that will create this struct, using TDLibKit
methods
Hope that helps
Thanks, made use of the repo directly but your method seems less cumbersome or heavy.
Hello, I am making use of an updatehandler to handle updates such as updateLastMessage and unable to update my list with the chat update due to "let" variable.
Here is an example of what I would like to do
Is there a better way to resolve or do we make a pull request?