Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SAP Fiori for iOS meet SAP Cloud Translation API

PS: Demo app at the end. I have not used the Fiori iOS assistant coding from scratch to understand things in detail.

So finally, I am back to share my new set of learnings while trying to get my head around SAP Fiori for iOS.  One of the most basic thing before even you think about starting is to spend at least 2-3 weeks in understanding what Swift is and how it works. Without it there is no point in just copy-pasting the tutorials. There are so many important concepts like delegate, protocol, dictionaries, mutable arrays etc. which needs to be understood clearly.

I have spent good amount of time in understanding Swift but still I feel I don’t understand it much..lolz. The key as always is we need to keep on learning and build up on our knowledge. Let me stop my rant get to the app which we have made.

What we are trying to make

We will be making a simple translation app to start the momentum in this blog, which will take input and translate it to the chosen language via SAP Cloud Translation Api.

Technical stuff used

  • FUISimplePropertyFomCell – Input field for text
  • FUIListPickerFormCell – Dropdown
  • FUIButtonFormCell – Button
  • SAPURL Session – Technique to communicate with Rest API’s
  • SAP API Hub – Translation – Our API

I would specifically like to thank Steve Guo for his  blog series and Robin van het Hof blog series which I have referred to get my head around the iOS development.

So, coming to the technical details we are using a navigation controller with a table view by default. Inside table view controller we are adding our Fiori based form elements. Once user clicks the translate button we call the SAP Cloud API for translation.

Demo

Challenges

  • First big challenge is the sample code in SAP API Hub for Swift does not work with my version of Xcode and Swift. I being a beginner in Swift it was tough to actually resolve the errors but was worth it.
  • Secondly Sample code for iOS Fiori is only available on an Ipad app and we have lack of examples online otherwise. I can understand we have just started this SDK and improving day by day.
  • Third biggest challenge for me was how to Parse the response from API. This actually led me to understand in detail about concept of dictionaries (nothing by key, value pair), mutable array (an array which can be changed after initial value assignment) and non-mutable one(non-changeable after initialization).Good use of casting was needed to get the translated text. The challenge comes you can see the whole response but don’t know how to traverse it.
 do {
guard  let responseObject = try JSONSerialization.jsonObject(with: data!, options:JSONSerialization.ReadingOptions.mutableContainers)as? NSDictionary else {
print("error trying to convert data to JSON")
 return
}
let root  = responseObject["units"] as? NSMutableArray
let contentDictionary : NSDictionary = root![0] as! NSDictionary
let translationArray  = contentDictionary["translations"] as? NSMutableArray
let decoded : NSDictionary = translationArray![0] as! NSDictionary
self.translationModel.outputData = decoded["value"] as! String

                 
  • Fourth biggest challenge for me was how to update the value which was returned by SAP Translation API. In my experience while working with Angular & Ionic the moment you update the model the changes are reflected. But in Swift world as far as my understanding till now is, I have to trigger it manually using the below mentioned code. Although 3 lines but took me good amount of time.
DispatchQueue.main.async {
  self.tableView.reloadData()
}

What is next?

  • Ofcourse more blogs to share the Swift Learning experience while using different controls and trying to mix different things:)
  • MIght be some basic Swift concepts for ABAPer’s

Feel free to provide your feedback open to all ears. I have also uploaded the code on Github it might help people who are starting the journey



This post first appeared on Web Service Testing A Blackjack GUI And API, please read the originial post: here

Share the post

SAP Fiori for iOS meet SAP Cloud Translation API

×

Subscribe to Web Service Testing A Blackjack Gui And Api

Get updates delivered right to your inbox!

Thank you for your subscription

×