0

I am trying to do a simple table scan with AWS and DynamoDB using Swift. I am new to apple programming and not sure what the issue is. The documentation for AWS SDK is all in objective C and the examples AWS give for Swift are rubbish.

The best info I got was from a question here so I have been trying to work through it.

Best way to make Amazon AWS DynamoDB queries using Swift?

There are too many error for one question so I will break it up into multiple questions:

The first part I tried to do is my class item which defines the mapping from the database "Item"

I have written my code and the errors I am getting underneath each line in bold:

    class Item : NSObject, AWSDynamoDBModel, AWSDynamoDBModeling { 

'Item' does not conform to protocol 'AWSDynamoDBModeling'

        var Artist              :   String = ""
        var SongTitle           :   String = ""
        var AlbumTitle          :   String = ""
        var Category            :   String = ""
        var PictureURL          :   String = ""
        var SongURL             :   String = ""
        var Location            :   String = ""
        var AVGMusicianRating   :   Int = 0
        var AVGUserRating       :   Int = 0
        var SongDuration        :   Int = 0
        var SongID              :   Int = 0

        override init!() { super.init() }

Failable initializer 'init()' cannot override a non-failable initializer

        required init!(coder:    NSCoder!) {
            fatalError("init(coder:) has not been implemented")
        }

        class func dynamoDBTableName() -> String! {
            return "Songs"
        }
        class func hashKeyAttribute() -> Int! {
            return SongID
        }

Instance member 'SongID' cannot be used on type 'Item' (My hash Key is an int not string)

        //required to let DynamoDB Mapper create instances of this class
        override init(dictionary dictionaryValue: [NSObject : AnyObject]!, error: NSErrorPointer)

Initializer does not override a designated initializer from its superclass

        {
                super.init(dictionary: dictionaryValue, error: error)
            }

            //workaround to possible XCode 6.1 Bug : "Type NotificationAck" does not conform to protocol "NSObjectProtocol"
            override func isEqual(anObject: AnyObject?) -> Bool {
                return super.isEqual(anObject)
            }

        }

Thanks in advance.

1 Answer 1

1

1. 'Item' does not conform to protocol 'AWSDynamoDBModeling'

Replace

class func hashKeyAttribute() -> Int! {
    return SongID
}

By

class func hashKeyAttribute() -> String! {
    return "SongID"
}

Explanation: You need to provide the name of the hashkey attribute, not it's type. The protocol requires that you return a String.

2. Failable initializer 'init()' cannot override a non-failable initializer

There is no need to extend NSObject. You can remove all init(..) methods from your code. As far as I can see they are not needed.

3. Instance member 'SongID' cannot be used on type 'Item' (My hash Key is an int not string)

This will go away when you fix error 1.

4. Initializer does not override a designated initializer from its superclass

This will go away when you fix error 2

I wrote a tutorial about using DynamoDB for a Swift app. Part 3 contains a simple example of a class AMZUser that is mapped to DynamoDB

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your help this does answer the question I asked. I have tried using your tutorial but unfortunately I have to do a full table scan. So I am forced to go back and work out how to do it in objective C. For such a large company you would think AWS could work out documentation that is relevant to the current standards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.