<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sandro Tola on Medium]]></title>
        <description><![CDATA[Stories by Sandro Tola on Medium]]></description>
        <link>https://medium.com/@sandro.tola?source=rss-172b04f47333------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*JH3ejPChA1VQvO5O</url>
            <title>Stories by Sandro Tola on Medium</title>
            <link>https://medium.com/@sandro.tola?source=rss-172b04f47333------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 18:13:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sandro.tola/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Profiling Flutter Apps, Part 1: A Practical Workflow]]></title>
            <link>https://insights.overapp.com/profiling-flutter-apps-part-1-a-practical-workflow-cdbef7040795?source=rss-172b04f47333------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdbef7040795</guid>
            <category><![CDATA[devtools]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Sandro Tola]]></dc:creator>
            <pubDate>Fri, 29 May 2026 09:02:46 GMT</pubDate>
            <atom:updated>2026-05-29T09:02:46.773Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Profiling Flutter apps (Part 1): A practical workflow</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tm4syCyIqqYrZe9LSWrcrA.png" /></figure><p>Flutter performance discussions usually begin with uncertain feedback:</p><blockquote>“This screen feels slow.”</blockquote><blockquote>“The animation stutters”, or</blockquote><blockquote>“it is slow on older devices”.</blockquote><p>The real challenge is not finding performance issues, but <strong>diagnosing</strong> them. We often end up making random optimizations: refactoring widgets, adding const, tweaking layout, hoping something improves, without understanding the <strong>root cause.</strong></p><p>Smooth Flutter apps are built on a simple habit: <br><strong>measure under the right conditions, analyse the frame data, and optimise only once you’ve pinpointed the bottleneck.</strong></p><h4>Start with the right setup</h4><p>Before you start opening any profiling tool, let’s make sure your setup is valid. Otherwise, everything that follows is useless.</p><p>There are three fundamental rules:</p><ul><li>Run the app in <strong>profile mode</strong></li><li>Always use a real physical device; do not use simulators</li><li>Reproduce a specific interaction at a time.</li></ul><p>Debug mode introduces extra work and can completely falsify performance. Simulators are useful for the development process, but they are not reliable indicators of real rendering performance.</p><p>If your measurement is wrong, so is your optimization.</p><h4>Understand Frames in Flutter</h4><p>Flutter renders your UI <strong>frame by frame</strong>,<strong> </strong>each with a limited time budget: approximately 16 milliseconds on 60 Hz devices and 8 milliseconds on 120 Hz devices.<br>If a frame exceeds this budget, it gets dropped, which users perceive as stutter or <strong>jank.</strong></p><p>The key mindset about frames is that they are divided into two main responsibilities:</p><ul><li>UI Thread: builds widgets, runs layout, and executes Dart code;</li><li>Raster Thread: paints pixels and composes the scene.</li></ul><p>When something feels sluggish, the real question is <strong>which part of the frame is using budget</strong>. Without this distinction, it’s difficult to pinpoint the problem.</p><h4>Using Flutter DevTools to answer the right question</h4><p>Opening <a href="https://docs.flutter.dev/tools/devtools/vscode">DevTools</a> for the first time can be overwhelming, with lots of data about each frame and a vast list of parameters.</p><p>The biggest mistake you can make is trying to understand everything at once. Instead, you can treat it as a diagnostic tool with a single goal: <strong>find a bad frame and figure out why it is slow.</strong></p><p>Approach it this way:</p><p>1: Open the Performance view.<br>2: Start recording.<br>3: Perform the interaction you want to debug.<br>4: Stop recording.<br>5: Look for irregularities in the frame char.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/0*rN4B5c3Llr-BXKAA.png" /></figure><p>Once you find a red frame, select it and check the time spent in the <strong>UI thread</strong> and the <strong>Raster thread</strong>.</p><p>At this stage, it’s crucial to apply fixes one at a time, focusing on the slower thread. Applying multiple fixes will only complicate matters. After applying a fix, repeat the test process and note any differences. <br><strong>Without measuring after a fix, you can’t truly assess whether you’ve made any improvements.</strong></p><p>DevTools offers many more panels, such as timeline events, flame charts, and CPU profiler, but you don’t need them all right away. Don’t worry, though, we’ll cover them in future articles.</p><h4>A real example: Investigating a janky list</h4><p>Let’s make this explanation clear with a simple scenario.<br>You have a screen with a list of items, and everything looks fine at first.<br>But as soon as you start scrolling, the UI stutters.<br>Let’s apply the workflow instead of guessing.</p><p><strong>Step 1: Reproduce and profile</strong></p><ul><li>Run the app in <strong>profile mode</strong></li><li>Use a <strong>real device</strong></li><li>Open DevTools → <strong>Performance view</strong></li><li>Scroll the list for a few seconds</li></ul><p><strong>Step 2: Find a bad frame</strong></p><p>Looking at the chart, you notice some red frames; let’s select one.<br>Now check the breakdown:</p><ul><li>The <strong>UI thread</strong> is taking most of the time.</li><li>The raster thread looks relatively stable.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m79P8EokdWRmJSYx.png" /></figure><p><strong>Step 3: Form a hypothesis</strong></p><p>Given that the issue happens during scrolling and the UI thread is busy, a likely cause is:</p><ul><li>Too many widgets are being built at once.</li><li>Rebuilding more than necessary.</li></ul><p><strong>Step 4: Inspect the code</strong></p><p>You look at the list implementation and find something like:</p><ul><li>a Column with many children or large scrollable content</li><li>or a ListView without a builder</li><li>or a list where each item is doing heavy work in build()</li></ul><p>This confirms the hypothesis:<br>The UI thread is overloaded because we’re building too much during scroll.</p><p><strong>Step 5: Apply one fix</strong></p><p>You replace the implementation with a lazy version, for example:</p><ul><li>switch to ListView.builder</li><li>ensure items are lightweight</li><li>avoid unnecessary rebuilds inside each item.</li></ul><p><strong>Step 6: Measure again</strong></p><p>Run the same profiling steps and look at the frame chart again.</p><p>This time:</p><ul><li>frame times are more consistent</li><li>no <strong>spikes</strong></li><li>UI thread work is <strong>significantly</strong> reduced</li></ul><h4>Conclusion</h4><p>Most Flutter performance issues are not difficult to fix; they’re difficult to <strong>identify correctly</strong>.<br>Once you follow this approach, performance work becomes faster, more predictable, and far less frustrating.</p><p>And that’s it; no magic tricks, just a better way to approach performance.<br>Thanks for sticking through the article, and see you in the next one 👋</p><p>Some <strong>sources</strong> you might find interesting:</p><ul><li><a href="https://docs.flutter.dev/perf/ui-performance?utm_source=chatgpt.com">Flutter performance profiling</a></li><li><a href="https://docs.flutter.dev/perf/best-practices?utm_source=chatgpt.com">Performance best practices</a></li><li><a href="https://docs.flutter.dev/tools/devtools/performance?utm_source=chatgpt.com">DevTools Performance view</a></li><li><a href="https://stackify.com/premature-optimization-evil/?utm_source=chatgpt.com">Why premature optimization is the root of all evil</a></li></ul><blockquote>If you liked this article, follow <a href="https://medium.com/u/fbe7e07cf9d2">OverApp</a> or visit our <a href="https://www.overapp.com/">website</a>.</blockquote><blockquote>by Sandro Tola, Mobile Developer at <a href="https://www.overapp.com/">OverApp</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdbef7040795" width="1" height="1" alt=""><hr><p><a href="https://insights.overapp.com/profiling-flutter-apps-part-1-a-practical-workflow-cdbef7040795">Profiling Flutter Apps, Part 1: A Practical Workflow</a> was originally published in <a href="https://insights.overapp.com/">OverApp</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enhancing SwiftUI Data Management with Realm]]></title>
            <link>https://insights.overapp.com/enhancing-swiftui-data-management-with-realm-82048307a2a3?source=rss-172b04f47333------2</link>
            <guid isPermaLink="false">https://medium.com/p/82048307a2a3</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[realmswift]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Sandro Tola]]></dc:creator>
            <pubDate>Mon, 12 Feb 2024 10:47:29 GMT</pubDate>
            <atom:updated>2024-02-12T10:47:29.136Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*ZZzJIzI3ndUXkTI6VPka7w.png" /></figure><p>The ability to store data persistently and create an intuitive user interface has become vital in the dynamic world of iOS development. Realm, a lightweight and powerful local database has become one of the most popular tools for developers looking for an efficient way to manage data. Its real-time functionality and user-friendly API make it a default solution for iOS apps. Combined with SwiftUI, Realm opens up new ways to create adaptive and data-centric apps that require less code but bring more performance.</p><p>SwiftUI, with its declarative nature, has transformed how developers create interfaces for iOS. Its plain text syntax makes UI creation easier to read and maintain, while also offering a set of tools for constructing sophisticated and dynamic layouts. Nevertheless, the real power of an application is often found in how well it handles and displays information. This is where Realm steps in, providing a convenient way to save data and retrieve it whenever needed while synchronizing with the UI components of SwiftUI.</p><p>The combination of Realm and SwiftUI provides an eloquent approach for the developers. It provides the capability to develop dynamic app experiences, with data management at its core. This synergy reduces the development process and improves the performance and scalability of iOS applications.</p><p>In this article, we will delve into the strategic integration of Realm within the SwiftUI framework. We will explore how this combination not only streamlines the development process but also augments the performance and scalability of iOS applications. From conceptual discussions to a practical case study of a <strong>to-do list </strong>application, we aim to provide insights into effectively harnessing the power of Realm with SwiftUI. Whether crafting a basic <strong>task manager</strong> or a complex platform, mastering the integration of Realm and SwiftUI is a crucial skill in the contemporary iOS development toolkit.</p><h3>The Evolution of Data Management in iOS Apps</h3><p>The landscape of data management in iOS development has evolved significantly over the years, marked by a notable shift from traditional solutions like CoreData to modern alternatives like Realm. CoreData, Apple’s framework, has been a staple in iOS data persistence due to its deep integration with the iOS ecosystem and robustness in handling complex data models and relationships. However, its steep learning curve has often posed challenges for developers.</p><p>Enter Realm, a newer player in the field, known for its simplicity and speed. One of the key advantages of Realm over CoreData is its ease of use. Realm simplifies object creation and data manipulation, allowing developers to write less code compared to the more boilerplate-heavy CoreData. This simplicity does not come at the cost of performance; in fact, Realm often outperforms CoreData.</p><figure><img alt="perforance comparison, in which realm is a lot faster" src="https://cdn-images-1.medium.com/max/700/1*_oBPl0Qx0RzUVnNCzy2JbA.png" /><figcaption>image taken from <a href="https://www.rockersinfo.com/realm-database-vs-core-data-what-is-best-for-android-ios/"><strong>this</strong></a> article</figcaption></figure><h3>Best Practices to follow</h3><p>When integrating Realm with SwiftUI, following certain best practices can significantly enhance the efficiency and effectiveness of your application development process. Here are three key best practices to consider:</p><ol><li><strong>Reactive Data Binding</strong>: Realm’s live objects are perfectly suited for SwiftUI’s reactive UI paradigm. By leveraging SwiftUI’s @ObservedObject and @Published property wrappers, your UI can automatically update in response to changes in the underlying data. This seamless integration ensures that your UI always remains in sync with your database state, eliminating the need for manual refreshes.</li><li><strong>Data Model Management</strong>: Realm’s approach to data model management is highly intuitive. Its models can be directly incorporated into SwiftUI views, greatly simplifying the creation and updating of UI components based on your data models. This simplicity speeds up the development process and enhances the maintainability of your code.</li><li><strong>Efficient Data Transactions</strong>: Realm excels in handling efficient data transactions, which is critical for maintaining data integrity and performance. It’s important to structure your data transactions and updates carefully, particularly in SwiftUI where views may update frequently. Use Realm wisely to ensure data consistency and avoid performance bottlenecks.</li></ol><p>Now, let’s explore a practical example by examining a To-Do List Application that I’ve developed. We’ll go through its setup and implementation, taking into account the principles and best practices previously discussed. This walkthrough will provide insights into how these concepts are applied in a real-world scenario.</p><h3>Case Study: A (To-Do List) Application</h3><p><a href="https://github.com/sandrotola/TaskManager"><strong>This Task Manager Application </strong></a>is a practical and user-friendly tool designed to assist individuals in managing their daily tasks and responsibilities. At its core, the app serves the fundamental purpose of enhancing productivity and organizational skills. The simplicity of a to-do list app makes it an ideal candidate for demonstrating key concepts in app development, particularly when integrating advanced technologies.</p><p>This application stands as a nice example to showcase the integration of Realm with SwiftUI for several reasons. Firstly, it involves fundamental data operations like creating, reading, updating, and deleting tasks (CRUD), essential in understanding database management. Realm excels in handling these operations with efficiency and simplicity, making it a suitable choice for the underlying data structure of the app.</p><p>Secondly, the dynamic nature of a to-do list, with tasks being added, modified, or marked as complete, provides a perfect scenario to illustrate the reactive data binding capabilities of SwiftUI in conjunction with Realm. This integration allows for real-time updates in the user interface as the underlying data changes, a crucial feature for maintaining an up-to-date and responsive application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*Q_iNPLRlfmqRv-CmYMX7sg.png" /></figure><p>The app is in the “empty” state. To add a task to our Database we can click on the “+” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*82igALhKAzXFM78yucqVgA.gif" /></figure><p>As you can see, the display of the newly created task is <strong>instant. </strong>Let’s see the implementation.</p><pre>//<br>//  AddNewTask.swift<br>//  TaskManager<br>//<br>//  Created by Sandro Tola on 07/02/24.<br>//<br><br>import SwiftUI<br>import RealmSwift<br><br>struct AddTaskView: View {<br>    @State private var taskName: String = &quot;&quot;<br>    @State private var taskType: String = &quot;&quot;<br>    @State private var startTime: Date = Calendar.current.startOfDay(for: Date())<br>    @State private var endTime: Date = Calendar.current.startOfDay(for: Date()).addingTimeInterval(60 * 60)<br>    <br>    @Binding var showModal: Bool<br>    var body: some View {<br>        NavigationView {<br>            Form {<br>                TextField(&quot;Task Name&quot;, text: $taskName)<br>                TextField(&quot;Task Type&quot;, text: $taskType)<br>                DatePicker(&quot;Start Time&quot;, selection: $startTime, displayedComponents: .hourAndMinute)<br>                DatePicker(&quot;End Time&quot;, selection: $endTime, in: startTime..., displayedComponents: .hourAndMinute)<br>                Button(&quot;Save Task&quot;) {<br>                    saveTask()<br>                }<br>            }<br>            .navigationBarTitle(&quot;Add New Task&quot;, displayMode: .inline)<br>            .navigationBarItems(trailing: Button(&quot;Cancel&quot;) { showModal = false })<br>        }<br>    }<br>    <br>    private func saveTask() {<br>        // Format date to get hours and minutes<br>        let formatter = DateFormatter()<br>        formatter.dateFormat = &quot;HH:mm&quot;<br>        <br>        // Prepare task to save<br>        let newTask = Task()<br>        newTask.name = taskName<br>        newTask.type = taskType<br>        newTask.startTime = formatter.string(from: startTime)<br>        newTask.endTime = formatter.string(from: endTime)<br><br>        // Call our Realm Manager to save the task in the local Database<br>        RealmManager.shared.addTask(newTask)<br><br>        // Close the modal<br>        showModal = false<br>    }<br>}</pre><p>The <strong>AddTaskView</strong> struct is a SwiftUI view that serves as a user interface for adding new tasks. It has <strong>several</strong> state variables: taskName, taskType, startTime, and endTime, which are bound to form fields, allowing the user to input the name and type of the task, as well as to select a start and end time.</p><p>A <strong>“Save Task”</strong> button is provided to trigger the <strong>saveTask</strong> function. This function formats the dates to extract hours and minutes, creates a new <strong>Task</strong> object with the entered details, and then calls “<strong>RealmManager.shared.addTask(newTask)</strong>” to save this task to the Realm <strong>database</strong>. After saving, the modal is dismissed by setting <strong>showModal</strong> to false.</p><pre>//<br>//  RealmManager.swift<br>//  TaskManager<br>//<br>//  Created by Sandro Tola on 07/02/24.<br>//<br><br>import RealmSwift<br><br>class RealmManager {<br>    // Singleton istance<br>    static let shared = RealmManager()<br><br>    // Realm istance<br>    private var realm: Realm<br><br>    // Start Realm<br>    private init() {<br>        do {<br>            realm = try Realm()<br>        } catch let error {<br>            fatalError(&quot;Realm can&#39;t be initialized: \(error.localizedDescription)&quot;)<br>        }<br>    }<br><br>    // Function to add a new Task to Realm<br>    func addTask(_ task: Task) {<br>        do {<br>            try realm.write {<br>                realm.add(task)<br>            }<br>        } catch let error {<br>            print(&quot;Error adding task: \(error.localizedDescription)&quot;)<br>        }<br>    }<br><br>    // Function to delete a Task from Realm<br>    func deleteTask(_ task: Task) {<br>        do {<br>            // Fetch the same task from the current Realm instance<br>            if let taskToDelete = realm.object(ofType: Task.self, forPrimaryKey: task.id) {<br>                try realm.write {<br>                    realm.delete(taskToDelete)<br>                }<br>            } else {<br>                print(&quot;Task not found or already deleted&quot;)<br>            }<br>        } catch let error {<br>            print(&quot;Error deleting task: \(error.localizedDescription)&quot;)<br>        }<br>    }<br><br>    // Function to edit a Task in Realm<br>    func updateTask(_ task: Task, with newTask: Task) {<br>        do {<br>            // Fetch the same task from the current Realm instance<br>            if let taskToUpdate = realm.object(ofType: Task.self, forPrimaryKey: task.id) {<br>                try realm.write {<br>                    taskToUpdate.name = newTask.name<br>                    taskToUpdate.type = newTask.type<br>                    taskToUpdate.startTime = newTask.startTime<br>                    taskToUpdate.endTime = newTask.endTime<br>                }<br>            } else {<br>                print(&quot;No Task with id \(task.id) found&quot;)<br>            }<br>        } catch let error {<br>            print(&quot;Error updating task: \(error.localizedDescription)&quot;)<br>        }<br>    }<br>}</pre><p>The <strong>RealmManager</strong> class is responsible for managing the Realm database operations. It is designed as a singleton to provide a consistent point of access to the Realm instance. The <strong>“addTask”</strong> function takes a <strong>Task</strong> object and performs a write transaction on the <strong>Realm</strong> instance to add the task to the database. There are also functions for deleting (<strong>“deleteTask”</strong>) and updating (<strong>“updateTask”</strong>) tasks.</p><p>Once the task is added, “<strong>@ObservedResult ” </strong>gets the new <strong>Task List</strong> and displays it instantly.</p><p>As previously said, the app performs <strong>edit</strong> operations also:</p><pre>struct MyTaskList: View {<br>    let tasks: [Task]<br>    @State private var activeTaskId: ObjectId?<br>    @Binding var showingAddTaskModal: Bool<br>    @State var showingEditTaskModal: Bool = false<br>    @State var selectedTask: Task = Task()<br><br>    var body: some View {<br>        VStack {<br>            HStack {<br>                Text(&quot;My Tasks&quot;)<br>                    .font(.largeTitle)<br>                    .bold()<br>                    .padding()<br>                Spacer()<br>                Button(action: {<br>                    showingAddTaskModal = true<br>                    activeTaskId = nil<br>                }) {<br>                    Image(systemName: &quot;plus.circle.fill&quot;)<br>                        .resizable()<br>                        .frame(width: 30, height: 30)<br>                        .foregroundColor(.pink)<br>                }<br>                .padding()<br>            }<br><br>            if tasks.isEmpty {<br>                Text(&quot;Your work for the day is done.&quot;)<br>                    .font(.headline)<br>                    .bold()<br>                    .padding()<br>            } else {<br>                ScrollView(showsIndicators: false) {<br>                    VStack(spacing: 10) {<br>                        ForEach(tasks) { task in<br>                            TaskCard(<br>                                task: task,<br>                                activeTaskId: $activeTaskId,<br>                                onEdit: {<br>                                    selectedTask.id = task.id<br>                                    selectedTask.name = task.name<br>                                    selectedTask.type = task.type<br>                                    selectedTask.startTime = task.startTime<br>                                    selectedTask.endTime = task.endTime<br>                                    activeTaskId = nil<br>                                    showingEditTaskModal = true<br>                                },<br>                                onComplete: {<br>                                    activeTaskId = nil<br>                                    RealmManager.shared.deleteTask(task)<br>                                }<br>                            )<br>                            .onLongPressGesture {<br>                                activeTaskId = (activeTaskId == task.id) ? nil : task.id<br>                            }<br>                        }<br>                    }<br>                    .padding()<br>                }<br>            }<br>        }<br>        .onTapGesture {<br>            activeTaskId = nil<br>        }<br>        .sheet(isPresented: $showingEditTaskModal) {<br>            EditTaskView(task: selectedTask, showModal: $showingEditTaskModal)<br>        }<br>    }<br>}</pre><p>Thanks to a<strong> Long Press Gesture</strong> on the Task Card the user can <strong>“select”</strong> a task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*JC2sKkatB3rMjCCN0U2tsQ.gif" /></figure><p>Upon selection, the <strong>Task Card </strong>reveals two options, edit and complete, each represented by universally recognized icons — <strong>a pencil</strong> for edits and <strong>a checkmark</strong> for completion. Tapping the pencil icon invokes the editing mode. This is where the seamless integration of Realm and SwiftUI <strong>shines</strong>.</p><p>The <strong>EditTaskView</strong> modal slides into view, populated with the task’s current details fetched from the Realm database. Here, the user is presented with the familiar fields of task name, type, and the start and end times ripe for modification.</p><p>As the user makes adjustments and hits “<strong>Save”</strong>, the <strong>magic</strong> of Realm’s real-time database updates the records. Behind the scenes, the RealmManager class performs the heavy lifting. It accesses the current Realm instance, finds the task by its unique identifier, and executes a write transaction. <br>The fields are updated with the new data, and upon completion, the modal dismisses itself, returning the user to their task list.</p><p>The <strong>beauty</strong> of this process lies in its <strong>fluidity</strong> — the user’s interaction with the task list is uninterrupted, and the updates appear to occur <strong>instantaneously</strong>. The reactive nature of SwiftUI means the UI is always a true reflection of the underlying data. There’s no need for a refresh button or a manual reload; the changes <strong>just appear</strong>, as if by magic.</p><p><strong>Lastly</strong>, the user can select a Task and <strong>mark it</strong> as <strong>“completed”:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*3Lb_ZMY9oaIXL0m9M4RkFQ.gif" /></figure><p>In this case, the <strong>checkmark</strong> button will just call the “<strong>deleteTask”</strong> from the Realm Manager.</p><h3>Conclusion</h3><p>In conclusion, the journey through the creation and refinement of this <strong>Task Manager</strong> Application has been an enlightening expedition into the possibilities of modern iOS application development. The seamless integration of Realm has demonstrated a <strong>significant</strong> reduction in the complexity typically associated with persistent local data storage and has showcased the <strong>dynamic</strong> capabilities of SwiftUI’s reactive user interface.</p><p>The exploration of functionalities like adding tasks in a few taps, editing them with ease, and finally marking them as complete with a satisfying tap <strong>illustrates</strong> the practicality and user-friendliness of combining Realm with SwiftUI. This case study serves as a testament to the <strong>powerful symbiosis</strong> between a database and a user interface, highlighting the ease with which developers can build responsive, data-driven applications.</p><p>Thank you for your time, and I will see you in my next article 😉.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82048307a2a3" width="1" height="1" alt=""><hr><p><a href="https://insights.overapp.com/enhancing-swiftui-data-management-with-realm-82048307a2a3">Enhancing SwiftUI Data Management with Realm</a> was originally published in <a href="https://insights.overapp.com/">OverApp</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generate images from text using OpenAI API in React Native]]></title>
            <link>https://insights.overapp.com/generate-images-from-text-using-openai-api-in-react-native-3e535a563324?source=rss-172b04f47333------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e535a563324</guid>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Sandro Tola]]></dc:creator>
            <pubDate>Tue, 23 May 2023 09:50:39 GMT</pubDate>
            <atom:updated>2023-05-29T15:42:14.032Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n9KwQDtw-rUSp2v2FvG40w.png" /></figure><p>In the recent period, we have all heard about new <strong>AI</strong> technologies such as <strong>ChatGPT</strong>, and as time goes on, those are being used to help developers in their work, sometimes just to resolve some issues, other times to develop all-around features in their projects.</p><p>It’s time to grasp some of these new technologies and learn how to put them to good use.</p><p><strong>🏆 What is our goal for today?</strong></p><p>Our goal is to create a simple application using React Native, that will take a user&#39;s text description about anything, and use a specific API called “createImage” released by <a href="https://platform.openai.com/docs/introduction"><strong>OpenAI</strong></a> to generate images related to that description. Should we start?</p><p><strong>Careful</strong>! This API is not free, as you need a paid account on OpenAI to use it.</p><p><strong>Step 1: Create a new app</strong></p><p>Firstly, let’s create a new project using <a href="https://docs.expo.dev/get-started/installation/"><strong>Expo</strong></a><strong>. </strong>Make sure you have everything you need.</p><p>Now run this command:</p><pre>expo init AIImageGenerator</pre><p><strong>Step 2: Start the server</strong></p><p>Open the project directory and start the server as follows:</p><pre>cd AIImageGenerator<br>expo start</pre><p><strong>Step 3: Install needed dependency:</strong></p><p>To use <a href="https://platform.openai.com/docs/introduction"><strong>OpenAI</strong></a><strong> </strong>API, we need to install the following dependency:</p><pre>expo install openai</pre><p>This dependency gives us access to every feature implemented by this technology</p><p><strong>Step 4: Open App.js and start writing some code:</strong></p><p>First of all, let’s configure everything we need to use the API:</p><p>The first step is to import Configuration and OpenAIApi from “openai”, as follows:</p><pre>import { Configuration, OpenAIApi } from &quot;openai&quot;;</pre><p>Then, we need to create a Configuration object, which will contain an apiKey, to authenticate ourselves to OpenAI:</p><pre>// Create a configuration object with your API key<br>const configuration = new Configuration({<br>  apiKey: &quot;YOUR API KEY HERE&quot;,<br>});</pre><p>OpenAI uses this key to authenticate every user that is trying to use their API, for that reason, I will not share mine, as it’s personal.</p><p><strong>⚠️ Be careful!</strong> You need to replace “YOUR API KEY HERE” with your actual key. To create one, you need to head <a href="https://platform.openai.com/account/api-keys"><strong>here</strong></a><strong> </strong>and click on “+ Create new secret key”. Make sure to save the key somewhere, because this will be the only time you can see it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*rBM3mCpHQaQrR1J5aWKYpA.png" /></figure><p>Lastly, we need to create an OpenAIApi object, using the configuration we created, as follows:</p><pre>// Create an instance of the API class<br>const openai = new OpenAIApi(configuration);</pre><p>OK, now we have everything we need to create our function that will handle the API call to create Images.</p><pre>// state variable &quot;result&quot; to help us track the result of the api call<br>// state variable &quot;text&quot; that will contain the prompt of the user<br>const [text, setText] = useState(&quot;&quot;);<br>const [loading, setLoading] = useState(false);<br>const [result, setResult] = useState(&quot;&quot;);<br><br>// Call the API to generate n images from a prompt<br>const generateImage = async () =&gt; {<br>  setLoading(true);<br>  try {<br>    const res = await openai.createImage({<br>      prompt: text,<br>      n: 1,<br>      size: &quot;512x512&quot;,<br>    });<br>    setLoading(false);<br>    setResult(res.data.data[0].url);<br>  } catch (error) {<br>    setLoading(false);<br>    console.error(`Error generating image: ${error}`);<br>  }<br>};</pre><p>Note that you can modify “<strong>size</strong>” and “<strong>n</strong>” as you wish. The first will change the <strong>size</strong> of the image we receive, and the second will change the <strong>number</strong> of images the API returns.</p><p><strong>Step 5: Create the UI</strong></p><p>We are getting there! We just need to create the <strong>UI</strong> to write a prompt and visualize an image:</p><pre>&lt;SafeAreaView style={styles.container}&gt;<br>  &lt;StatusBar style=&quot;light&quot; /&gt;<br>  &lt;View&gt;<br>    &lt;Text style={styles.title}&gt;<br>      Give a detailed description of what you want to create.<br>    &lt;/Text&gt;<br>    &lt;TextInput<br>      style={styles.textInput}<br>      onChangeText={(text) =&gt; setText(text)}<br>      placeholder=&quot;Describe your idea&quot;<br>      placeholderTextColor=&quot;#fff&quot;<br>      multiline={true}<br>      numberOfLines={4}<br>    /&gt;<br><br>    {/* Show loading indicator while generating image */}<br>    {loading ? &lt;ActivityIndicator color={&quot;white&quot;} /&gt; : &lt;&gt;&lt;/&gt;}<br><br>    {/* Show image if generated */}<br>    {result.length &gt; 0 ? (<br>      &lt;Image style={styles.image} source={{ uri: result }} /&gt;<br>    ) : (<br>      &lt;&gt;&lt;/&gt;<br>    )}<br><br>    &lt;TouchableOpacity<br>      title=&quot;Generate Image&quot;<br>      onPress={generateImage}<br>      disabled={loading}<br>    &gt;<br>      &lt;Text style={styles.text}&gt;Generate new Image&lt;/Text&gt;<br>    &lt;/TouchableOpacity&gt;<br>  &lt;/View&gt;<br>&lt;/SafeAreaView&gt;</pre><p>and now the <strong>style</strong>:</p><pre>const styles = StyleSheet.create({<br>  container: {<br>    flex: 1,<br>    backgroundColor: &quot;#0c0c0c&quot;,<br>  },<br>  title: {<br>    color: &quot;#fff&quot;,<br>    fontSize: 20,<br>    fontWeight: &quot;bold&quot;,<br>    padding: 20,<br>  },<br>  textInput: {<br>    color: &quot;#fff&quot;,<br>    backgroundColor: &quot;transparent&quot;,<br>    padding: 20,<br>    fontSize: 16,<br>    marginTop: 20,<br>    fontWeight: &quot;bold&quot;,<br>    textAlign: &quot;center&quot;,<br>  },<br>  image: {<br>    width: 350,<br>    height: 350,<br>    alignSelf: &quot;center&quot;,<br>    marginTop: 40,<br>  },<br>  text: {<br>    color: &quot;white&quot;,<br>    fontSize: 20,<br>    fontWeight: &quot;bold&quot;,<br>    alignSelf: &quot;center&quot;,<br>    marginTop: 40,<br>  },<br>});</pre><p>The <strong>result</strong> should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DekyYLHqN2jXgQy2DTgwog.png" /></figure><p><strong>We did it</strong>! We successfully used OpenAI API to create an image from a description given by the user. Now you can explore more this new technology by yourself. <strong>Have fun!</strong></p><p>Here is the <strong>full code</strong>: <a href="https://github.com/sandrotola/AIImageGenerator">AIImageGenerator</a></p><p>Thank you for your time, and a special thanks to <a href="https://medium.com/@franceska.leskaj"><strong>Franceska</strong></a>, for providing the beautiful illustration at the top of my article.</p><p>See you in my next article 😉.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e535a563324" width="1" height="1" alt=""><hr><p><a href="https://insights.overapp.com/generate-images-from-text-using-openai-api-in-react-native-3e535a563324">Generate images from text using OpenAI API in React Native</a> was originally published in <a href="https://insights.overapp.com/">OverApp</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>