iOS Install specific iOS beta on simulator Apple release the new iOS SDK every day, as the developer, we want to test our apps on those new SDK before they are officially released. For example, we want to have the iOS 17 beta on the MacOS Ventura 13.3 (22E252). Here are the steps: First need to
iOS How to do a deep cleaning for pod If you are like me, the project is still using the pod to manage the libraries and frameworks. We need to clean the projects from time to time. The following command can help us to clean all the cached pods. In the root directory: pod deintegrate pod cache clean --all
Swift Nested class in Swift A nested class in Swift is a class that is defined within another class. Some key features: * Nested class have access to local variables or constants of the outer class unless these variables or constants are marked as static. * Nested class can be marked as private, fileprivate, or internal. Here
RxSwift 2 hours to master RxSwift - Part 2 In this article we will dig a bit more depth in some core concepts on 2 hours to master RxSwift - Part 1. Section 1: Observable Like mentioned in the last article, an Observable in RxSwift will emit events (values and errors) over time, and notifies its observers, and nearly
RxSwift 2 hours to master RxSwift - Part 3 Introduction In the previous post: 2 hours to master RxSwift - Part 1 (needone.app) and 2 hours to master RxSwift - Part 2 (needone.app), we get to know the the core concept behind the RxSwift and how RxSwift works. In this tutorial, we are going to combine what
Swift Featured 2 hours to master RxSwift - Part 1 a simple introudction on rxswift, including what is rxswift, how to use it and a quick example (with swift code) on demo that.
Swift Generic type vs. Any in Swift Generic type In Swift, a generic type is a placeholder for a specific type that is specified when the generic type is used. A generic type allows you to write flexible and reusable code that can work with any type, while still taking advantage of type safety. For example, you
iOS indirect enum in Swift An indirect enum in Swift is an enum that can be used to define a recursive data structure. This means that one or more of its cases can refer to an instance of the same enum type. Here is an example of an indirect enum in Swift: indirect enum TreeNode&
Swift UITraitCollection UITraitCollection is a class in the UIKit framework that defines a set of interface traits that specify the environment in which your app is running. These traits include the device’s display scale, user interface style, and size class. You can use the information contained in a UITraitCollection object to
Swift UIKit vs. SwiftUI - A general discussion UIKit and SwiftUI are two different frameworks for building user interfaces on Apple platforms. UIKit UIKit is the older of the two frameworks, and has been around since the early days of iOS development. It is a mature and powerful framework that provides a wide range of tools and APIs
Swift Sort custom objects by property in Swift Many of us have met the situation that we have an array/list of custom objects, and we want them can be sorted in a specific order. For example, we are have a group of people, and we want to sort the whole array by the person's age.
Swift Format currency in Swift Recently I have done quite an amount of work on formatting currency in Swift project, here are some tricks on how to format number in Swift: Format currency with auto currency symbol By using the NumberFormatter class, we can convert numbers into string(s), and vice versa. More conveniently, we
iOS Get the current week in Swift To get the current week in Swift 5, you can use the Calendar and DateComponents classes to calculate the week number for the current date. Here's an example of how you might do this: let calendar = Calendar.current let currentDate = Date() let currentWeek = calendar.component(.weekOfYear, from: currentDate)
iOS SceneDelegate In iOS, the SceneDelegate is a class that is responsible for managing the scenes in your app. A scene is a discrete unit of your app's user interface, such as a window or tab. The SceneDelegate class provides methods that are called at various points in the lifecycle
Swift Data Racing in Swift A data race in Swift occurs when two or more threads access the same memory location simultaneously and at least one of them is writing to it, without proper synchronization. This can lead to unexpected behavior or crashes in your program. In Swift, there are two common scenarios on data
SwiftUI @AppStorage vs. @UserDefault in SwiftUI Both the @AppStorage and @UserDefault property wrappers in SwiftUI allow you to store and retrieve data using UserDefaults. However, there are a few key differences between the two: @AppStorage In SwiftUI, you can use the @AppStorage property wrapper to store and retrieve data using UserDefaults. The @AppStorage property wrapper binds
Swift Get location coordinates using CLLocationManager in Swift To get the location (latitude and longitude) of a device in Swift, you can use the Core Location framework, which is an official library from Apple. Only 2 steps are required, so it is pretty simple: Step 1: Set up proper permission To get the location of a device in
Swift Encode URL in Swift It is quite common to see that we can correctly set up the HTTP header, token, body and POST/GET methods in our iOS code, but we still can't get the right response. Here is an error which most of people encounter before, incorrect url encoding. Sometimes the
Swift Nested method in Swift A nested method in Swift is a method or function that is defined within another function. Nested functions have the following characteristics: * They have access to all variables and constants of the outer function, including local variables and parameters. * They do not have access to variables or constants in the
iOS Popup alert in Swift As mentioned in the other article: Popup Custom View in UIKit: popup mainly can be: * popup an alert using UIAlertController * popup action sheet using UIAlertController. For more details, check this: Present action sheet in UIKit and SwiftUI * popup a custom view/viewController A popup dialog is a component that displays
Swift Popup Custom View in UIKit In UIKit, popup mainly can be: * popup an alert using UIAlertController * popup action sheet using UIAlertController. For more details, check this: Present action sheet in UIKit and SwiftUI * popup a custom view/viewController The following will demonstrate how to present a custom view/viewController by creating a custom popup by
iOS Compiler directives in Swift This post is going to list some of the most frequently used compiler directives in Swift, compatible in Swift 3/4/5. Someone might call this preprocessor directives, but they are the same concept. In this post, we list few commonly used directives with detailed examples: Updated in 2022 #sourceLocation
Swift Present action sheet in UIKit and SwiftUI An action sheet is a component that displays a set of choices to the user in a modal format. UIKit In iOS, you can create an action sheet using a UIAlertController with the .actionSheet style. Here is an example of how to create an action sheet in Swift: let actionSheet
Swift What is keyword defer in Swift The defer keyword in Swift is used to execute a block of code at the end of the current scope, regardless of how the scope is exited. The defer block is executed after any return statements, and before any finally blocks. Here is an typical example of how to use
iOS Command pattern in Swift Many of us have heard about the Command pattern or used them in the development, which is a behavioral design pattern in which an object is used to encapsulate all of the information required to perform an action or trigger an event at a later time. This information includes, for