Skip to main content

Posts

Building an elegant Routing Layer in SwiftUI

SwiftUI empowers developers with powerful APIs to design user interfaces, making it easier than ever to create visually stunning screens that enhance the user experience (UX). Once these screens are crafted, the next step is to seamlessly connect them using navigation tools like NavigationView or NavigationStack . But here’s the catch: navigation logic can quickly spiral into a tangled mess as your app scales with more features and screens. The challenge lies in writing a clean, maintainable routing layer that keeps your codebase organized and easy to extend. To tackle this, adopting a dedicated routing layer is essential, especially when working with structured app architectures like VIPER or MVVM. In VIPER, routing plays a pivotal role as the "R" in the acronym. In MVVM, however, routing often takes a backseat in SwiftUI projects. This article introduces a simple yet effective approach to integrate a routing layer within SwiftUI, ensuring your app’s navigation logic rem...

Transformative impact of VisionOS on education

VisionOS gives futuristic opportunity in Education and Training landscape. For instance illustrating virtual classrooms, interactive learning environments, and simulations. 1. Immersive Learning Environments: VisionOS introduces immersive learning environments that go beyond traditional classroom setups. These environments leverage augmented reality (AR) and virtual reality (VR) technologies to create realistic and engaging educational experiences. Students can explore historical events or conduct virtual experiments, fostering a deeper understanding of the subject matter. 2. Redefining Traditional Education Models: The traditional education model often relies on lectures, textbooks, and static presentations. VisionOS disrupts this paradigm by offering dynamic and interactive content. Teachers can create 3D models, simulations, and interactive lessons, providing students with a more engaging and participatory learning experience. 3. Interactive and Engaging Platform: VisionOS is design...

Successfully installing CocoaPods in M1 Macs

Installation steps of cocoapods in the new Macs with M1 chipset is little different than Intel based Macs. If we casually run `pod install`, we are likely to encounter error related to the ffi gem 🤨. Open the terminal and follow below steps to solve the error and install pod dependencies successfully. Step1 : At first, install ffi gem intel version > sudo arch -x86_64 gem install ffi Steps 2: Install cocoapod  > sudo gem install cocoapods Steps 3 (optional) : Go to project root folder and initialise pod file if not created already. > arch -x86_64 pod init Steps 4: Now Install pod dependencies. > arch -x86_64 pod install

HackerRank Exercise : Kangaroo Number Line Jumps Solved in Swift 5.0

Given two kangaroos on a number line ready to jump in the positive direction, we have to figure out a way to get both kangaroos at the same location at the same time as part of the show. If it is possible, return YES , otherwise return NO . Read full problem statement from here Working solution in Swift           func kangaroo ( x1 : Int , v1 : Int , x2 : Int , v2 : Int ) -> String {         var multiplier = 1         // 1.         while (multiplier < 10000 ) {             // 2.             if (x1+(v1*multiplier) == x2+(v2*multiplier)) {                 return "YES"             }                          multiplier += 1         }            ...

HackerRank Exercise: Subarray Division solved in Swift 5

 In this post we can see complete solution for the HackerRank Exercise Subarray Division. The problem statement goes like this - Determine how many ways can divide the chocolate bar (as contiguous segment) between Lily and Ron given condition :  The length of the segment matches Ron's birth month The sum of the integers on the squares is equal to his birth day. Read complete challenge detail from HackerRank Working solution in Swift given below:      func birthday ( s : [ Int ] , d : Int , m : Int ) -> Int { var sCount = 0 var index = 0 // 1 while ( index < s. count ) { var dayLength = 0 let limit = index +m > s. count ? s. count : index +m // 2 for jIndex in index ..< limit { dayLength += s [ jIndex ] } // 3 if dayLength == d { sCount += 1 } ...

HackerRank Exercise: Apple and Orange solved in Swift

 In this post we can solve exercise problem "Apple and Orange" in which we should print the number of apples and oranges that land on Sam's house.  Read complete challenge detail from  hackerrank.com Full Swift Solution is given below: func countApplesAndOranges ( s : Int , t : Int , a : Int , b : Int , apples : [ Int ] , oranges : [ Int ]) -> Void { // 1 let applesDistance = apples. map ( { $ 0 + a }) var totalAppleOk = 0 applesDistance. forEach ({ ad in // 2 if ( s .. . t ) . contains ( ad ) { totalAppleOk = totalAppleOk + 1 } }) print ( " \( totalAppleOk ) " ) // prints number of Apples let orangeDistance = oranges. map ( { $ 0 + b }) var totalOrangeOk = 0 orangeDistance. forEach ({ od in if ( s .. . t ) . contains ( od ) { totalOrangeOk = totalOrangeOk ...

Hackerrank Exercise : Utopian Tree solved in Swift

In this post, we have Swift 5.0 solution for Hackerrank exercise - Utopian Tree . We have find out the height of  Utopian Tree, which goes through 2 cycles of growth every year. Each spring, it doubles in height. Each summer, its height increases by 1 meter. Full details of exercise link  hackerrank.com/challenges/utopian-tree/problem Here is the working solution:           func   utopianTree ( n :   Int )   ->   Int   {          var   height   =   0          for   cycle   in   0 .. . n   {              height   =   ( cycle   -   1 )   %   2   ==   0   ?   height   *   2   :   height   +   1            }  ...