Open in app

Sign in

Write

Sign in

Hasancan Akgündüz
Hasancan Akgündüz

162 Followers

Home

About

Jun 25, 2022

Swift 5.7 Regex and RegexBuilder

Apple introduced RegexBuilder with Swift 5.7. It helps us create regexes to use in operations like searching a pattern in a text. I will demonstrate this with a task and its solution with RegexBuilder. The task is to find all the words starting with vowel characters(a, e, i , o…

IOS

2 min read

Swift 5.7 Regex and RegexBuilder
Swift 5.7 Regex and RegexBuilder
IOS

2 min read


May 15, 2022

RxSwift Memory Leak While Passing Functions to Operators

In RxSwift, we should be careful while passing functions to operators which might cause a memory leak. In this example, our main actor is RxSwiftTest class. It creates an observable in init and passes multiplyByTwo function to map operator to transform the result. Passing the function causes observable to keep a strong reference to RxSwiftTest instance and RxSwiftTest can not get deallocated and subscription keeps living and printing the result:

Swift

1 min read

RxSwift Memory Leak While Passing Functions to Operators
RxSwift Memory Leak While Passing Functions to Operators
Swift

1 min read


May 15, 2022

RxSwift Memory Management

I will show the example first: In this example, we have an Observable emitting events every 300 milliseconds and a Disposable that is returning as the result of subscribe function. Here, although our view controller does not keep a strong reference for this subscription, the console keeps printing events:

Swift

1 min read

RxSwift Memory Management
RxSwift Memory Management
Swift

1 min read


May 4, 2022

Combine Future

Let’s say we have 2 business logics and one needs the other ones’ output to process. Here in this case we can get help from Future in Combine: The business logic functions returns Future, we tie them up with flatMap and then subscribe with sink function. See that we erased the Future type to AnyPublisher using eraseToAnyPublisher to make it more flexible. Now, the business logics might return error, in that case we can handle it in many ways with combine. One way of handling would be:

Swift

1 min read

Combine Future
Combine Future
Swift

1 min read


May 3, 2022

Combine PassthroughSubject and CurrentValueSubject

One difference between them is CurrentValueSubject has an initial value and emits the latest value to new subscribers. I will show with an example. First, the PassthroughSubject: As you see, subscription2 does not get any value since PassthroughSubject does not emit latest value. Now, the CurrentValueSubject: See that…

Swift

1 min read

Combine PassthroughSubject and CurrentValueSubject
Combine PassthroughSubject and CurrentValueSubject
Swift

1 min read


Mar 12, 2022

Async Await in Swift

Apple introduced a new way of handling asynchronous tasks using async and await keywords. Basically, we mark the asynchronous functions with async and call them with await keyword. The old way of handling asynchronous tasks using completion closures has an important downside that we have to call the callback in…

IOS

2 min read

Async Await in Swift
Async Await in Swift
IOS

2 min read


Mar 12, 2022

SwiftUI LazyHStack vs HStack

If we want to load the content into memory when we need it, we can use LazyHStack. It is particularly useful when we have large list of contents inside a scrollview. Here’s how our regular HStack looks like: HStack has 1000 Text content in it and the background color of HStack is blue:

Swiftui

2 min read

SwiftUI LazyHStack vs HStack
SwiftUI LazyHStack vs HStack
Swiftui

2 min read


Feb 26, 2022

SwiftUI LazyVStack vs VStack

If we want to load the content into memory when we need it, we can use LazyVStack. It is particularly useful when we have large list of contents inside a scrollview. Here’s how our regular VStack looks like: VStack has 1000 Text content in it and the background color of VStack is blue:

IOS

2 min read

SwiftUI LazyVStack vs VStack
SwiftUI LazyVStack vs VStack
IOS

2 min read


Dec 30, 2021

SwiftUI Drawing Custom Shapes

In SwiftUI, shapes are built using paths. To create a custom shape we need to conform to Shape protocol and do the drawing inside path(in:) function. The parameter function takes is a rectangle and it is the reference to the frame that the shape is going to reside. Let’s draw a Cross: And add it into a VStack to test it out: Here’s the result:

Swiftui

1 min read

SwiftUI Drawing Custom Shapes
SwiftUI Drawing Custom Shapes
Swiftui

1 min read


Dec 27, 2021

SwiftUI Environment Property Wrapper

We can get system-wide settings like color scheme(light or dark), size class, device locale using @Environment property wrapper. The full list for the values/settings we can access are here: https://developer.apple.com/documentation/swiftui/environmentvalues Let’s see an example: Here, we have two environment values: colorScheme and verticalSizeClass. We change text color according to colorScheme and we switch between VStack and HStack according to verticalSizeClass.

Swiftui

1 min read

SwiftUI Environment Property Wrapper
SwiftUI Environment Property Wrapper
Swiftui

1 min read

Hasancan Akgündüz

Hasancan Akgündüz

162 Followers

iOS Developer

Following
  • Kenneth Reilly

    Kenneth Reilly

  • C C Farley

    C C Farley

  • Darrin Atkins

    Darrin Atkins

  • Artturi Jalli

    Artturi Jalli

  • AltexSoft Inc

    AltexSoft Inc

See all (2,075)

Help

Status

About

Careers

Blog

Privacy

Terms

Text to speech

Teams