4D for Mobile: Build Great Mobile Apps Using Computed Attributes

Automatically translated from English

As you probably know, computed attributes are available starting from 4D v19 R3. A blog post is available that presents this great new feature.

As we always propose the best and complete user experience to our mobile app developers, computed attributes are compatible with all your iOS and Android projects. 

This means that as soon your getters are defined, you can use them as any other field in your mobile app creation process. So you’ll be able to visualize and publish them from the Structure section of the mobile project editor. This is a considerable improvement when it comes to displaying more relevant information in your mobile app, avoiding splitting an address into several fields for example.

Let’s see how it works with an example. We’ll display a computed fullname field with a first name and last name and a fulladdress computed field using a street number, city, and country fields.

4D side

As you can see in the structure, a FirstName and a LastName attributes are available. We want to display “FirstName LastName” in our mobile app. 

In the same way, we have a StreetNumber, an Address, and a Location attributes. And we want to display “StreetNumber  Address – Location.”

For that, let’s extend the ContactEntity class:

Class extends Entity
exposed Function get fullName->$result : Text
 $result:=This.FirstName+" "+This.LastName
exposed Function get fullAddress->$result : Text
 $result:=This.StreetNumber+" "+This.Street+" - "+This.Location

Now let’s go back to the mobile project editor.

Project editor side

As you can see in the project editor, your computed attributes are now available from the structure section, ready to be published and used as any other field in the creation process.

This means that you can use them in the Data section to filter your data, add an icon, as well as short and long labels. You can also use them as action parameters as soon as a setter is available. Still, in this example, it was more relevant to use single attributes in action forms to make editing easier.

Now let’s build our app!

Mobile app side

In our final app, both single attributes and computed attributes are displayed.

So as you can see, this new feature allows more advanced use of the existing templates and displays more information in a relevant way.

Don’t hesitate to give us feedback on the 4D forum, and check out the documentation for more details!

David Azancot

• 4D for iOS Product Owner •

David Azancot joined the 4D Product team as a Product Owner in 2017. He's in charge of writing the user stories and translating them into functional specifications. His role also includes making sure that feature implementations meet customers' needs.

David graduated with an MBA in Marketing, Internet and Mobility from the Leonard De Vinci Institute and began his career in 2011 with a mobile start-up company, later acquired by Madvertise (a mobile marketing group). Passionate about mobile interfaces, he was the natural choice to develop interactive mobile ad formats for the group in 2015. In parallel, David has been developing his own iOS and Android applications since 2012.