Skip to content

Instantly share code, notes, and snippets.

View BalajiMalliswamy's full-sized avatar
🏠
Working from home

Balaji Malliswamy BalajiMalliswamy

🏠
Working from home
View GitHub Profile
@BalajiMalliswamy
BalajiMalliswamy / CheckPalindrome.Swift
Created April 26, 2022 16:05
Given the string, check if it is a palindrome.
//Given the string, check if it is a palindrome.
//Example
// For inputString = "aabaa", the output should be
// solution(inputString) = true;
// For inputString = "abac", the output should be
// solution(inputString) = false;
// For inputString = "a", the output should be
// solution(inputString) = true.
@BalajiMalliswamy
BalajiMalliswamy / centuryFromYear.swift
Created April 26, 2022 16:01
Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200
//Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200, etc.
//Example
// For year = 1905, the output should be
// solution(year) = 20;
// For year = 1700, the output should be
// solution(year) = 17.
func solution(year: Int) -> Int {
@BalajiMalliswamy
BalajiMalliswamy / AlertWithTextInput.swift
Last active May 30, 2018 07:26
Exploring UIAlertController in swift
/**
Simple Alert with Text input
*/
func showAlertWithTextField() {
let alertController = UIAlertController(title: "Add new tag", message: nil, preferredStyle: .alert)
let confirmAction = UIAlertAction(title: "Add", style: .default) { (_) in
if let txtField = alertController.textFields?.first, let text = txtField.text {
// operations
print("Text==>" + text)
}
@BalajiMalliswamy
BalajiMalliswamy / AlertWith3Buttons.swift
Last active May 30, 2018 07:23
Exploring UIAlertController in swift
/**
Simple Alert with more than 2 buttons
*/
func showAlertWithThreeButton() {
let alert = UIAlertController(title: "Alert", message: "Alert with more than 2 buttons", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Default", style: .default, handler: { (_) in
print("You've pressed default")
}))
@BalajiMalliswamy
BalajiMalliswamy / AlertWithDistructive.swift
Last active May 30, 2018 07:26
Exploring UIAlertController in swift
/**
Simple Alert with Distructive button
*/
func showAlertWithDistructiveButton() {
let alert = UIAlertController(title: "Sign out?", message: "You can always access your content by signing back in", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default, handler: { _ in
//Cancel Action
}))
alert.addAction(UIAlertAction(title: "Sign out",
@BalajiMalliswamy
BalajiMalliswamy / SimpleActionSheet.swift
Last active May 30, 2018 07:27
Exploring UIAlertController in swift
/**
Simple Action Sheet
- Show action sheet with title and alert message and actions
*/
func showSimpleActionSheet(controller: UIViewController) {
let alert = UIAlertController(title: "Title", message: "Please Select an Option", preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Approve", style: .default, handler: { (_) in
print("User click Approve button")
}))
@BalajiMalliswamy
BalajiMalliswamy / SimpleAlert.swift
Last active March 15, 2023 12:30
Exploring UIAlertController in Swift
/**
Simple Alert
- Show alert with title and alert message and basic two actions
*/
func showSimpleAlert() {
let alert = UIAlertController(title: "Sign out?", message: "You can always access your content by signing back in", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default, handler: { _ in
//Cancel Action
}))
@BalajiMalliswamy
BalajiMalliswamy / Alerts.swift
Created May 30, 2018 06:49
Example for show different types of Alerts in iOS
//
// Alerts.swift
// ExploringUIAlertView
//
// Created by Balaji Malliswamy on 30/05/18.
// Copyright © 2018 NFNLabs. All rights reserved.
//
import UIKit
//
// ViewController.swift
// StackoverflowWorks
//
// Created by Balaji Malliswamy on 03/03/17.
// Copyright © 2017 NFNLabs. All rights reserved.
//
import UIKit