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 } ...
Recently I published a countdown app . At one point of development - I have to show a timer on a UILabel which ticks on each seconds. As usual I started setting text to a label object - self .timerLabel.text = someString Easy piece of cake right !? But wait ... it won't take much user attention when timer ticks on every seconds. So I decided to make use of a simple animation while label gets text update. I found there are dozens of ways to animate a label. In this short article, I listed 3 best way you can animate text on a label. ( Spoiler Alert 👀- I decided to go with 3rd option) 1. Fade In - Fade out animation : CATransition class has got transition type `fade`. With timing function of CATransition - I was able to see the below result. let animation: CATransition = CATransition () animation.timingFunction = CAMediaTimingFunction (name: CAMediaTimingFunctionName .easeInEaseOut) animation.type = CATransitionType .fade animation.subtype = C...