Tag Archives: swiftProgramming

How to animate SF symbols?

By | October 24, 2024

SwiftUI provides the symbolEffect() modifier to add built-in animation effects for SF Symbols and produce a real touch of delight with almost no effort. For example, we could animate a dog icon up and down with a gentle bounce whenever a button is pressed. You could also try .pulse to animate the opacity, but where things get really clever is when… Read More »

How to fill and stroke basic shapes in swiftUI?

By | October 9, 2024

In latest iOS versions ( ios 17 onwards) we can directly put stroke and fill shapes just by adding modifiers one after another as shown below. It works with multiple strokes of various sizes as shown below. In older versions of iOS ( iOS 16 ) SwiftUI provides the fill(), stroke(), and strokeBorder() modifiers for adjusting the way we… Read More »

How to add image as background in swiftUI?

By | October 4, 2024

In swiftUI, apple doesn’t provide any dedicated background image or color modifier. It lets us add any kind of background view using its background() modifier. For example, this creates a text view with a large font, then places a 100×100 image behind it. However, it doesn’t need to be an image all the time. For example, this… Read More »

How to expose swift class to react native class?

By | September 10, 2024

There will be situations where you have to expose your Swift class to React Native. To do this, you need to use some Obj-C Macros available in React Native. To use these Obj-C Macros, you need a new Obj-C file: You have to import RCTBridgeModule, so that you can use the Macros to bridge the native… Read More »

How to adjust text alignment using multilineTextAlignment()

By | August 13, 2024

Like many other text UI’s SwiftUI’s Text wraps across multiple lines, they align to their leading edge by default. You can change that behavior, by using swiftUI’s ‘multilineTextAlignment()’ modifier to specify an alternative like .center, .trailing etc. For example, this will center several lines of text as they wrap across lines: Let’s use a picker… Read More »

How do I implement pull to refresh in SwiftUI?

By | June 11, 2024

There are two main approaches to implementing pull-to-refresh functionality in SwiftUI, depending on your SwiftUI version and desired level of customization: 1. Using the built-in refreshable modifier (iOS 16+) If you’re targeting iOS 16 and above, SwiftUI offers a built-in refreshable modifier that simplifies pull-to-refresh functionality for List and ScrollView. Here’s how to use it:… Read More »

How to use ‘AsyncImage’ in swiftUI?

By | May 27, 2024

AsyncImage is a component introduced in SwiftUI to handle the loading and displaying of remote images asynchronously. It simplifies the process of fetching images from the web, handling the loading state, and displaying a placeholder until the image is ready. Here’s a detailed breakdown of how AsyncImage works, its customisation options, and usage examples. Basic… Read More »

What are higher order functions in swift ?

By | February 28, 2024

Higher-order functions in Swift are functions that take other functions as parameters or return functions as output. They enable a functional programming style by allowing you to compose functions, pass behavior as arguments, and manipulate collections with concise and expressive code. Here are some common higher-order functions in Swift with examples: map(_:): filter(_:): reduce(_:combine:): sorted(by:):… Read More »

What is inout parameter in swift?

By | January 24, 2024

In Swift, inout is a keyword used to indicate that a parameter is passed by reference and can be modified inside a function, affecting the original value outside the function. This allows a function to modify the value of the parameter and have those changes reflected in the calling scope. Here’s an example to illustrate… Read More »