Skip to main content

Posts

Showing posts from 2019

Execute a method when a variable value changes in Swift

This post is about how to execute a function when a variable value changes. Instead of key-value observation, simply use a property observer for the variable.  For e.g: Whenever the value of variable named  allSlot  changes, the two lines will execute which are written in the  didSet  method. private var allSlot : [S tring ] = [] {         didSet {             slotTableView?.reloadData()             enableRightBarButton()         }      } Property observers:  https://docs.swift.org/swift-book/LanguageGuide/Properties.html#//apple_ref/doc/uid/TP40014097-CH14-ID262

How to apply custom font on attributed HTML text

Today, I came across a very challenging situation which yields into a great learning by end of the day. Let me give you more details about this to you. Task: I am getting attributed HTML text which already has multiple tags like bold and line break. I want to show the attributed text in custom font keeping the existing tags. Problem: When I applied custom font on attributed text, the existing tags like bold and line break overrides. Solution: I found a style tag which needs to apply on the attributed text. let modifiedFont = String (format: "<span style=\"color:#000000;font-family: '-apple-system', 'SFProText-Regular'; font-size: \( self . font ?. pointSize ?? 14.0 ) \">%@</span>" , htmlText) Code example: extension UITextView {     func setHTMLFromString (htmlText: String ) {         let modifiedFont = String (format: "<span style=\"color:#000000;font-family: '-apple-system&#

How to work with Charles proxy server

In this post, I am going to share a technique which will help you in debugging your mobile application code effortlessly even if your server is down. To set up the Charles server, follow the below steps:            ·     Install the free Charles software from  https://www.charlesproxy.com/download/ ·    Open Charles, go to Tools -> Map local ·    In map local window/popup, click add. Add the relevant details like Host, Port(8080), Path, Query of URL. ·    Under "map to" option:- Select the local JSON file ·    Click done and a popup will look like this: (location will have the URL string, the local path will have the path of JSON file) ·    Now go to Tools - Rewrite ·    In the rewrite popup, Select the "Enable rewrite option" and add the previous URL here ·    Add the following rewrite rule ·    Click ok and apply all the settings. ·    Now run the application in simulator and API's response will be read f