Posts

Stored and Computed Properties in Swift

Image
1,  Stored Properties The simplest form of a variable declaration provides only a type.  Stored variables must be initialized before use. As such, an initial value can be provided at the declaration site.  "A stored property is one that saves a value for use later." var count : Int 2, Computed  Properties A  computed variable  behaves syntactically like a variable, but does not actually require storage.    compute the value by providing a  getter   and an optional   setter  to retrieve and set other properties and values indirectly rather than storing values directly. get { } :  When retrieving the value of a property this block of code will get executed. set { } :  When setting the value of a property this part of code will get executed. "A computed property is one that runs some code in order to calculate the value." var variableName: dataType { get { //code to execute return someValue } set (newValue) {

What is Tuple in Swift

Image
What is Tuple? A tuple is a group of zero or more values represented as one value. Tuples in Swift are like mini  structs  and should be used for storing temporary values only.  They are commonly used to return multiple values from a function call.  Tuple is value types. When you initialize a variable tuple with another one it will actually create a copy. In swift we have two types of tuples are available those are  unnamed  tuples and  named  tuples.  Unnamed Tuples In swift,  unnamed tuples  are used to group multiple values into single by using parentheses and those are need to be separated by commas.  let userData = ( "Pawan Manjani" , 200 ) print(userData.0) //Pawan Manjani print(userData.1) //200       2 .    Named Tuples In swift,  named tuples  are used to group multiple values into single by using parentheses and need to define those values with named variables and those are separated

What is Generics in Swift

Image
What is Generics? Generic enables you to write flexible, reusable functions and types that can work with any type, subject to requirements that you define. Generics are used to avoid duplication and to provide abstraction. Generics are type safe, meaning if you pass a string as a generic and try to use as a integer the compiler will complain and you will not be able to compile your code. (This happens because Swift is using  Static typing , and is able to give you a  compiler  error ) If you use AnyObject the compiler has no idea if the object can be treated as a String or as an Integer. It will allow you to do whatever you want with it. 'Arrays' and 'Dictionary' types belong to generic collections. With the help of arrays and dictionaries the arrays are defined to hold 'Int' values and 'String' values or any other types. There is just one rule if y ou want to make your function generic. All you need to do is put  <anythin

What is typealias in Swift

Image
What is type alias?  A type alias allows you to provide a new name for an existing data type into your program. Type alias does not create new types they simply provide a new name to an existing type. The main purpose of type alias is to make our code more readable.     Example: typealias Name = String let firstName:Name = "Pawan" Thanks for reading, Happy Coding 👨‍💻

How to use: Map, Filter and Reduce in Swift

Image
1, Map The Map is an extension method on Sequence and Collection. The map function returns an array containing the results of applying a mapping or transform function to each item. let cast = [ "Vivien" , "Marlon" , "Kim" , "Karl" ] let lowercaseNames = cast. map { $ 0 .lowercaseString } // 'lowercaseNames' == ["vivien", "marlon", "kim", "karl"] 2, Filter It Returns an array containing, in order, the elements of the sequence that satisfy the given predicate.  It’s a very useful operation which allows us to filter the existing collection  and return an Array containing only those elements that match an include condition. let cast = [ "Vivien" , "Marlon" , "Kim" , "Karl" ] let shortNames = cast. filter { $ 0 . count < 5 } // return only names which have shorter than five characters print (shortNames) // Prints "["Kim&qu

SKStore​Review​Controller Swift

Image
In order to display Rate/Review inside the app. You can ask users to rate or review your app while they're using it, without sending them to the App Store.You determine the points in the user experience at which it makes sense to call the API and the system takes care of the rest. Steps to use  SKStore Review Controller in our project You have to import StoreKit framework. import StoreKit  Ask for review by SKStoreReviewController . requestReview () Example import StoreKit func DisplayReviewController { if #available( iOS 10.3,*){ // Note: SKStoreReviewController is available in iOS 10.3 and later SKStoreReviewController . requestReview () } }

How to use UITableView

Image
How to use UITableView in iOS using Objective-c Step:1- Select Single view Application Step:2- Give Project name  Step:3- Drag and drop UITableView Step:4- Right click your tableview and set datasource and delegate method Step:5- Declare array in .h file Step:6- Write these code in .h file Step:7- Finally Command+r to run your code 

Get data from .plist file in Swift

Image
Get data from .plist file(Swift) Step:1- Select Add New file  Step:2- Select Property List from it and give the name of it  Step:3- Add some data in .plist file  Step:4- Add finally write code for it like first get the path of plist in string and get content of file by giving it path string and finally you will get data of plist