Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

[TwilioChatClient] Swift interface looks sketchy at best #20

Open
tmspzz opened this issue Jul 20, 2017 · 9 comments
Open

[TwilioChatClient] Swift interface looks sketchy at best #20

tmspzz opened this issue Jul 20, 2017 · 9 comments

Comments

@tmspzz
Copy link
Contributor

tmspzz commented Jul 20, 2017

Hi,

we are currently considering Twilio for a large chat application but the TwilioChatClient Swift interface looks sketchy at best.

Consider these lines from TCHChannel:

    /** Optional channel delegate */
    weak open var delegate: TCHChannelDelegate!

Am I looking at production code? Is there a newer version of the SDK I should be looking at?
I am Currently on 0.16.1

Is this the right forum where to ask questions?

@otymartin
Copy link

@blender
https://www.twilio.com/docs/api/chat/changelogs/ios

@tmspzz
Copy link
Contributor Author

tmspzz commented Jul 20, 2017

@otymartin Thanks! However does not seem like this has changed much (looking at 1.0.4)

/** Optional channel delegate.  Upon setting the delegate, you will receive the current channel synchronization status by delegate method. */
    weak open var delegate: TCHChannelDelegate!

@otymartin
Copy link

otymartin commented Jul 20, 2017

@blender Im failing to understand your problem with that delegate declaration? weak open car delegate: TCHCHannelDelegate!?

@tmspzz
Copy link
Contributor Author

tmspzz commented Jul 20, 2017

Since the delegate is weak it can be nil at any moment. Accessing it by channel.delegate when this is declared implicitly unwrapped can cause a segmentation fault at any moment (if in fact it happens to be nil).

It is good practice (and much safer) to declare delegates as weak and optional.

 weak open var delegate: TCHChannelDelegate?

I am going around this by defining in an extension

extension TCHChannel: ChatChannelWithDelegate {

    public weak var optionalDelegate: TCHChannelDelegate? {
        
        guard let delegate = self.delegate else { return nil }
            
        return delegate
    }
 }

Poking around this gives me very little confidence is the status of the SDK and the abstractions that one can build around it.

@otymartin
Copy link

@blender Good find, it completely went over my head.
@rbeiter

@tmspzz
Copy link
Contributor Author

tmspzz commented Jul 20, 2017

I am guessing it's just a matter of adding proper nullability annotations to the objc sdk.
Swift has been around for quite some time now.

If anyone from Twilio reads this please let me know if this is the right forum or if I should be discussing this elsewhere. Thanks.

@rbeiter
Copy link
Contributor

rbeiter commented Jul 21, 2017

Hi @blender - I'm on the team taking care of the iOS Chat SDK's. This is indeed related to not having nullability hints in the Obj-C interfaces and addressing this is already in process for 2.x which is coming soon. We'll update this issue when 2.0 is released. Let us know here or through our support portal (https://support.twilio.com/) if we can assist further. Thanks!

@tmspzz
Copy link
Contributor Author

tmspzz commented Jul 21, 2017

@rbeiter Thank you very much. Looking forward to the changes.

@tmspzz tmspzz closed this as completed Jul 21, 2017
@tmspzz
Copy link
Contributor Author

tmspzz commented Aug 31, 2017

@rbeiter TCHMessage timeStampAsDate is nil for this string 2017-08-17T15:34:30.513Z

Since timeStampAsDate is Date! this causes a crash. Twilio chat 1.0.7.

See proper ISO date parsing here: https://github.com/cheeyi/ProjectSora/blob/master/Pods/AFDateHelper/AFDateHelper/AFDateExtension.swift

@tmspzz tmspzz reopened this Aug 31, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants