Example of using throws and do-catch and try to handle errors in Swift
Throwing functions in Swift
To indicate that a function can throw error you just add the word “throws” after its parameters and before its return type.
It is then called a throwing function. Continue reading “Error handling using throws and do-catch in Swift”
Using NSCoding, NSKeyedArchiver and NSKeyedUnarchiver to save array of custom objects to NSUserDefaults
NSCoding protocol enables an object to be encoded or decoded for archiving and saving to disk.
It declares two methods that your object must implement in order to be encoded and decoded. Continue reading “How to save Array of custom objects to NSUserDefaults”
In fact Array and Dictionary are generic collections, this is why you can create an Array of Int , String or any other type
What are Generics
Generics are one of the most powerful features of Swift, It allows you to create flexible Functions and Types that can work with any type.
If you used Array or Dictionary before in Swift then you already knows about Generics.
In fact Array and Dictionary are generic collections, this is why you can create an Array of Int , String or any other type and the same with Dictionary. Continue reading “What exactly are Generics”
Also called Type Properties
What is Static property
We all know Instance Properties that belong to an instance of type and every time you create an instance of that type it has its own property value. Continue reading “Static properties in Swift”
What is it? when and how to use it
What is Singleton
Singleton is a design pattern that guarantees that only one instance of a class can be instantiated. Continue reading “Singleton in Swift”
Learn about private, fileprivate, public and internal
Use it to restrict access to parts of your code from code in another modules or files.
You can assign access levels to Classes, Structs, Enumerations in addition to their Properties, Initializers, Methods and Subscripts. Continue reading “Access control in Swift”
UITextView is a scrollable, multiline text region and its object : “textContainer” defines where the text will be laid out. Continue reading “Remove top padding from UITextView”
Add gradient background to UIView using CAGradientLayer
CAGradientLayer is a layer that draws gradient color over its background.
By default color are spread evenly but you can control the locations of them.
The following function will add a gradient layer to the view passed to it Continue reading “Create UIView with gradient background”
A list of all fonts in iOS and learn how to get them in Swift
This is a list of all font names in iOS and how to get them Continue reading “All font names provided by iOS”
Easily detect the absence of value in variable or constant using Optionals
Optional is an enum that has 2 states, the first state is where there is a value and that value is of some type for example Int, and the other state is nil where there is no value at all. Continue reading “Optionals in Swift”