试图将值附加到字典

时间:2017-06-08 17:08:55

标签: ios swift dictionary

尝试将值附加到字典

private static SyncAdapter sSyncAdapter = null;
private static final Object sSyncAdapterLock = new Object();

    @Override
    public void onCreate() {
        synchronized (sSyncAdapterLock) {
            if (sSyncAdapter == null) {
                sSyncAdapter = new SyncAdapter(getApplicationContext(), true);
            }
        }
    }

我对成员'下标'在public typealias Parameters = [String: Any] var parameters: Parameters = [ "username" : username, "first_name" : firstName, "last_name" : lastName, "profession" : profession ] if let imageURl = imageUrl { parameters[4] = ["image_url" : imageUrl] }

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

您应该通过parameters密钥访问String字典,即"image_url",而不是其索引4:

if let imageURl = imageUrl {
    parameters["image_url"] = imageUrl
}