Cannot use mutating member on immutable value of type

后端 未结 6 1333
被撕碎了的回忆
被撕碎了的回忆 2021-01-01 09:04

I have following struct:

public protocol SuperModel {
    // empty protocol
}
struct ModelOne: SuperModel {
    struct SubModelOne {
        var someVar: Dou         


        
6条回答
  •  耶瑟儿~
    2021-01-01 09:40

    Use like this,

    struct UserAttributes {
    var name:String?
    var organizationID:String?
    var email:String?
    
    mutating func parseUserAttributes(attribues:[AWSCognitoIdentityProviderAttributeType])->UserAttributes{
    
        for type in attribues{
            if type.name == "name"{
                name = type.value
            }else if(type.name == "family_name"){
                organizationID = type.value
            }else if(type.name == "custom:role_id"){
                role = type.value
            }else if(type.name == "email"){
                email = type.value
             }
    
         }
    
       }  
     }
    

    In some other file call like this,

    var userAttributes = UserAttributes()
    userAttributes = userAttributes.parseUserAttributes(attribues:attributes)
    

提交回复
热议问题