我正在尝试执行一个查询,我想要检索所有具有2个定义值之间的高度和宽度的项目,如下所示:
let queryExpression = AWSDynamoDBQueryExpression()
queryExpression.filterExpression = ":widthSmall < #width < :width AND :heightSmall < #height < :height"
queryExpression.keyConditionExpression = "#addedByType = :addedByType"
queryExpression.expressionAttributeNames = ["#addedByType": "addedByType", "#width": "widthSmall","#height": "heightSmall","#width": "width","#height": "height"]
queryExpression.expressionAttributeValues = [":addedByType": "APPUSER", ":widthSmall": 50, ":heightSmall": 50, ":width": 100, ":height": 100]
queryExpression.scanIndexForward = false
queryExpression.limit = 200
这会因为expressionAttributeNames
而抛出以下错误fatal error: Dictionary literal contains duplicate keys
检查的正确方法是什么?
答案 0 :(得分:0)
好的,经过相当多的试验和错误,我已经弄清楚我做错了什么,并得出以下结果:
queryExpression.filterExpression = ":widthSmall < #width1 AND #width < :width AND :heightSmall < #height1 AND #height < :height"
queryExpression.keyConditionExpression = "#addedByType = :addedByType"
queryExpression.expressionAttributeNames = ["#addedByType": "addedByType", "#width1": "width","#height1": "height", "#width": "width", "#height": "height"]
queryExpression.expressionAttributeValues = [":addedByType": "APPUSER", ":widthSmall": 50, ":heightSmall": 50, ":width": 101, ":height": 101]
问题是我在词典中引用了两次相同的键