Skip to content

Instantly share code, notes, and snippets.

View hitendradeveloper's full-sized avatar
PRO

Hitendra developer hitendradeveloper

PRO
View GitHub Profile
@hitendradeveloper
hitendradeveloper / ProtocolExample6.swift
Created December 16, 2018 18:53
Protocol Example - 6 : Protocol as a super-type : Medium blog
import Foundation
//MARK:- InformationDisplayble Protocol
protocol InformationDisplayble {
func displayInformation()
}
//MARK:- Employee Class
class Employee {
var employeeID: String = "EMP007"
@hitendradeveloper
hitendradeveloper / AnyObjectExample1.swift
Created July 14, 2018 08:25
AnyObject + ClassTypes - Example1
import Foundation
//MARK:- Person
class Person {
var firstName: String = "Hitendra"
var lastName: String = "Solanki"
}//End: Person
//creating instances | objects as a person type
let person1: Person = Person()
@hitendradeveloper
hitendradeveloper / ProtocolExample5.swift
Last active June 14, 2018 21:10
Protocol Example - 5 : Protocol Composition using new protocol - alternate way : Medium blog
import UIKit
protocol HSCombineTableViewDatasourceDelegate : UITableViewDataSource, UITableViewDelegate { } //empty protocol
class ContactListViewController: UIViewController {
//ContactListViewController implementation
}
extension ContactListViewController: HSCompositeTableViewDatasourceDelegate {
//implementation of methods releated to UITableViewDataSource and UITableViewDelegate
@hitendradeveloper
hitendradeveloper / ProtocolExample4.swift
Created May 24, 2018 19:44
Protocol Example - 4 : Protocol Composition : Medium blog
import UIKit
typealias HSCompositeTableViewDatasourceDelegate = (UITableViewDataSource & UITableViewDelegate)
class ContactListViewController: UIViewController {
//ContactListViewController implementation
}
extension ContactListViewController: HSCompositeTableViewDatasourceDelegate {
//implementation of methods releated to UITableViewDataSource and UITableViewDelegate
@hitendradeveloper
hitendradeveloper / ProtocolExample3.swift
Last active May 24, 2018 19:34
Protocol Example - 3 : Multiple protocol extensions of a class : Medium blog :
class PlacesMapViewController: UIViewController {
//PlacesMapViewController implementation
}
extension PlacesMapViewController: MKMapViewDelegate {
//implementation of methods releated to mapView
}
extension PlacesMapViewController: UISearchBarDelegate {
//implementation of methods releated to searchbar
}
@hitendradeveloper
hitendradeveloper / ProtocolExample2.swift
Last active July 14, 2018 06:35
Protocol Example - 2 : Medium blog
import Foundation
protocol Displayable {
func displayName()
}
class Person {
var name: String
init(name: String) {
self.name = name
@hitendradeveloper
hitendradeveloper / ProtocolExample1.swift
Created May 18, 2018 19:15
Simple Protocol Confirmation
import Foundation
protocol Displayable {
//protocol requirements
}
class Person: Displayable {
//class implementation
}
@hitendradeveloper
hitendradeveloper / InheritanceExample.swift
Last active July 14, 2018 08:22
Inheritance Example 2
import Foundation
//MARK:- Person, Super class
class Person {
var firstName: String = "Hitendra"
var lastName: String = "Solanki"
var displayString: String {
return "Name of person is \(firstName) \(lastName)."
}
@hitendradeveloper
hitendradeveloper / LoginViewController.swift
Last active February 25, 2019 09:00
Simple sub-class example
import UIKit
class LoginViewController: UIViewController {
//your class implementation
}
@hitendradeveloper
hitendradeveloper / TypeCastExample1.swift
Last active May 15, 2018 17:36
type-casting simple example 1
var intValue: Int = 5
var doubleValue: Double = 7.0
var addition = Double(intValue) + doubleValue //addition will be implicitly considered of type Double by swift compiler