Skip to main content

Posts

Showing posts from April, 2017

What are the differences between Constant and Variables in swift

A lot of people can't figure out how to declare variable and constant in swift so today this tutorial i want to writing about constant and variable Only the first part of the statement is different: You declare constants using let, whereas you declare variables using var you can use almost any character you like for constant and variable names including Unicode characters: number = 4 let 🐶🐮 = "dog cow" Constant and variable names cannot contain mathematical symbols arrows private-use(or invalid) unicode code points or line and box-drawing character nor can they begin with a number ,although number may be included elsewhere within the name once you have declared a constant or variable of a certain type ,you contain type ,you can't redeclare it again with the same name or change it to store values of a different type.Nor can you change a constant into a variable or a variable into constant you can change the value of an existing variable to anothe...

How to UICollectionView in swift

this tutorial i want to show you how to use " UICollectionView " in swift ready to get started and go to File->New->Project and select iOS->SingleView Application click Next to fill out information about the application Set the Product Name " Colectionview " Company Identifier : KienPhamDev It’s actually the domain name written the other way round.if you have domain,you can use your own domain name otherwise you may use mine or just fill in Device family :you can chose universal it’s not important Choose swift as Language Click Next to select the project location, and then click Create Starting your Colectionview: open Main.storyboard and drag in a Collection view Controller.go to Editor\Embed in\ Navigation Controller to creat a Navigation Controller and automatically set the collection view controller as the root we can drag   Ui imageview and Lableview from the Object Library at fist,we have to create a new file and go to...

How to use Dictionary in Swift

Swift dictionary are specific about the types of keys and values they can store the number.They differ from Objective C 's NSDictionary and NSMutableDictionary classed ,which can use any kind of object as their key and values and do not provide any information about the nature of these object .in Swift ,the type of key and values that a particular dictionary can store is alway made clear ,either though an explicit type annotation od through type difference swift's dictionary type is write as Dictionary <Key type,valuetype > where key type is kind of value that can be used as a dictionary key and Value type is type of value that the dictionary stores for those key Dictionary literal we can initialize a dictionary with dictionary literal,which has similar syntax to the array literal seen earlier .A dictionary literal is a shorthand write one or more key value pairs as a dictionary collection dictionary has a key and value in a dictionary in a dictionary lit...

How to creating an Array in Swift

this tutorial i want to show you "Array" in swift step by step you can create an emty array of a certain type using initializer syntax: var number = [ Int ] () Note that the type of the number variable is inferred to be Int[], because it is set to the output of an Int[] initializer the example below create an array called shoppinglist to store String values: var shoppinglist:[ String ] = [ "Eggs" , "Milk" ]; the shoppinglist variable is declared as "an array of String value", written as string[],because this particular array has specified a value type of string it is only allowed to store string values here,the shoppinglist array is initialized with two string values ("eggs"and "milk"), written within an array literal. use the add a new item to the end of an array by calling the array's append method: number . append ( 5 ) shoppinglist . append ( "Apple" ) you can also appe...