Category Archives: Apple

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 »

How to setup a basic core data stack in swift?

By | February 22, 2024

Setting up a Core Data stack in Swift involves several steps, including creating a managed object model, setting up a persistent store coordinator, managed object context, and other components. Here’s a basic guide to setting up a Core Data stack in Swift: Create a Data Model: Generate NSManagedObject Subclasses: Initialize the Persistent Store Coordinator: Managed… Read More »

What is enum associated values in swift?

By | February 15, 2024

In Swift, enumerations (enums) are powerful constructs that allow you to define a group of related values. Associated values in Swift enums enhance their flexibility by enabling each enum case to carry additional data of varying types. This feature allows you to model more complex data structures and behaviors with enums. Here’s how you can… Read More »

What is protocol oriented programming in swift?

By | February 7, 2024

Protocol-oriented programming (POP) is an approach to software development in Swift that emphasizes the use of protocols to define interfaces and behavior, promoting code reuse, flexibility, and composability. POP encourages structuring code around protocols rather than classes, focusing on what types can do rather than what they are. Key concepts of protocol-oriented programming in Swift… Read More »

What is XCTest framework in iOS?

By | February 5, 2024

The XCTest framework is the testing framework provided by Apple for writing and running unit tests in iOS and macOS applications. It is part of the broader XCTest framework available in the Apple ecosystem. XCTest is commonly used with Swift and Objective-C to test various aspects of your code, ensuring its correctness, reliability, and maintainability.… Read More »

What is a frame and bounds of a UIView in swift?

By | February 1, 2024

In iOS development using UIKit, a UIView is a fundamental building block for constructing the user interface. Two important properties of a UIView are its frame and bounds. These properties define the size and location of the view within its superview. frame: In this example, myView is positioned at (50, 50) within its superview, and… Read More »

Theming your App in Flutter using BLoc, Save & Reload

By | December 6, 2020

In this article, we will see how we can use BLoc to Theme your app in Flutter. To understand BLoC with a real world example, you can refer to my previous post on BLoC here. Part 1 Part 1 For this demo also we will need the below plugins If you follow my previous tutorial,… Read More »

Using WKWebkit in iOS – Simple Example

By | December 2, 2018

Whenever you want to show a webpage in your iOS App, use WKWebview instead of UIWebview. You have to supply an url that is complete. ie. with “http” or “https”. If you are using “http”, make sure you enable the “App Transport Security Settings” and add “Allow Arbitrary Loads” to yes.     Our Final… Read More »

How to configure Firebase Google-Services.json for different targets in iOS?

By | November 3, 2018

Once you have different Google-Services.json for different targets for your firebase applications, you may be wondering how all can have same filenames and configure for different targets. However the solution is simple. Initial Steps * Create new directory for each directory inside for project folder. Make sure the folder name is different from the target… Read More »

How to listen to events from react native?

By | August 14, 2018

Hi friends, This is essentially a continuation of this post http://www.coderzheaven.com/2018/08/10/how-to-create-a-custom-native-imageview-in-android-for-reactnative/ Now we will listen to a click event from the image we just created. For that we have to add the ClickListener to the image in Android. Add below methods to the java class On the React Native Side The whole java class will… Read More »

How to create a custom native ImageView/View in Android or iOS for ReactNative?

By | August 10, 2018

Many times we need custom components from native. Here is a simple example on how to create a custom imageview in Android for react native. First we will start with the Android Version Android Create a class that extends SimpleViewManager. Write a setSrc method which accepts the source url from React Native. Implement ‘createViewInstance’ method… Read More »

Awesome React Native Image Caching Libraries

By | August 4, 2018

Image Loading and caching had been a little bit pain in react native. In-fact react native didn’t had native support for caching. But after the recent release, there is now support for caching in iOS only. Still not for Android. You can read more about this from here https://facebook.github.io/react-native/docs/images.html#cache-control-ios-only Now these are the variety of… Read More »

AutoConnect to Wi-Fi in iOS

By | May 5, 2018

Apple has introduced a new API in iOS 11 where you can directly connect to a Wi-Fi from with-in the app. For this code to work 1. you need to enable the networking capabilities in your provisioning profile. 2. Once you enable the networking profile in the provisioning profile, you need to regenerate and sign… Read More »

Special characters that can be included in a Swift String ?

By | January 5, 2018

Special characters can be included in string literals using the following escape sequences: The following example shows how to use a few string literals: Swift 4 Escape sequence Meaning \0 Null Character \\ \character \b Backspace \f Form feed \n Newline \r Carriage return \t Horizontal tab \v Vertical tab \’ Single Quote \” Double… Read More »

How to Count characters in a String in Swift 4?

By | December 20, 2017

To retrieve a count of the characters in a string, call the global countElements function and pass in a string as the function’s sole parameter: prints “sampleString has 32 characters” Note : Different Unicode characters and different representations of the same Unicode character can require different amounts of memory to store. Because of this, characters… Read More »

How Type Safety is implemeted in Swift 4?

By | December 15, 2017

Swift 4 is a type-safe language which means if a part of your code expects a String, you can’t pass it an Int by mistake. As Swift 4 is type-safe, it performs type-checks when compiling your code and flags any mismatched types as errors. Playground execution failed: error: :6:6: error: cannot assign to ‘let’ value… Read More »

Simple Alert with two buttons in iOS Swift with callback

By | December 1, 2017

Dear Friends, Today I will show you how to create a simple alert with two buttons and how to write a callback for each button. The code is simple. Its written for Swift 3. Send your comments to coderzheaven@gmail.com

Class has not initialiser error in Swift – Solved.

By | August 14, 2017

Apart from other languages, when you write a class in Swift, It should have a initialiser. To solve this we have to write init() function in that particular class. Just like below. For example, look at the below class. Here we have 5 variables. The above error usually comes when you don’t initialize all variables… Read More »

Custom TimerView in iOS – Swift

By | April 10, 2017

Hello everyone, Here in this tutorial I will show you how you can create a Custom View for Timer without any layout in Swift. Custom Timer Class Our Custom timer class will look like this Here I am passing the superview in which timerview is going to be placed as the parameter. Then I am… Read More »