Reputation: 263
I am following this Getting Started guide for building an iOS app using the AWS Amplify CLI and the AWS SDK for iOS.
And I had previously followed the steps in this Apple Getting Started guide for simply creating the basic framework for a Single View Application.
Everything works without a hitch: I was able to build my empty project in Xcode, launch the simulator, see my white blank screen, both before and after starting the AWS iOS SDK Swift tutorial.
My problem is that the AWS tutorial presumes more Swift knowledge than I have. So when it says the following toward the end—
Call the runMutation(), runQuery(), and subscribe() methods from your app code, such as from a button click or when your app starts in viewDidLoad().
—the guide has essentially skipped some steps.
I've already created the required AWS resources for this tutorial but I don't know how to call the functions and update the DynamoDB table that gets set up.
Assuming I can add two text fields to the UI View (one for the ToDo 'name' and one for the 'description') and tie a button to them, can someone help me go the rest of the way?
UPDATE Answered below. I received a down-vote for asking this question, but one might argue that a Getting Started guide should be self-contained. No biggie; I worked across the two tutorials and solved my problem and posted an answer for those who are confused as I was.
Upvotes: 5
Views: 1410
Reputation: 263
So, I was able to successfully complete the AWS Amplify / iOS SDK Getting Started guide after leveraging the Apple iOS Swift Getting Started guide to create the necessary view elements required by AWS. What that means is this:
Two text fields: 'name' and 'description'; a label; and a button. Here are my outlet properties:
//MARK: Properties
@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var descTextField: UITextField!
@IBOutlet weak var todoItemLabel: UILabel!
My viewDidLoad():
override func viewDidLoad() {
super.viewDidLoad()
// Handle the text field’s user input through delegate callbacks.
nameTextField.delegate = self
descTextField.delegate = self
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appSyncClient = appDelegate.appSyncClient
}
My button action which calls runMutation():
//MARK: Actions
@IBAction func addToDoItem(_ sender: UIButton) {
runMutation()
}
And changes to runMutation() to update DynamoDB with the entered values:
let mutationInput = CreateTodoInput(name: nameTextField.text ?? "No Entry", description: descTextField.text)
If you have followed Steps 1 - 4 of the AWS Amplify / iOS SDK Getting Started guide and added the necessary UI elements then the code above will seal the deal.
Also note that the API reference pointed at by @dennis-w in the comments above takes care of those deprecated references in AppDelegate from the Getting Started guide.
Upvotes: 4