Skip to content

Instantly share code, notes, and snippets.

extension ViewController: MFMessageComposeViewControllerDelegate {
func showMessageComposeViewController() {
guard MFMessageComposeViewController.canSendText() else {
print("SMS services are not available")
return
}
let messageComposeViewController = MFMessageComposeViewController()
messageComposeViewController.messageComposeDelegate = self
messageComposeViewController.body = "Your text here"
@sanketfirodiya
sanketfirodiya / IUO.swift
Created April 14, 2017 18:27
Dangers of implicitly unwrapped optionals
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
class ViewController: UIViewController {
lazy var tapHandler: TapHandler = TapHandler(delegate: self, view: self.view)
}
extension ViewController: TapHandlerDelegate {
//
// NavigationBarProfileImage.swift
// Tuity-iOS
//
// Created by Sanket Firodiya on 5/30/16.
// Copyright © 2016 Tuity. All rights reserved.
//
import UIKit
//
// ImageProvider.swift
// Tuity-iOS
//
// Created by Sanket Firodiya on 7/13/16.
// Copyright © 2016 Tuity. All rights reserved.
//
import UIKit
import Foundation
extension UITextField {
func containsOnlyNumbers(string: String, maximumDecimalPlaces: NSInteger, maximumValue: NSInteger) -> Bool {
// Check that textfield only contains allowed number of decimal places (this can also be done in regex, but avoiding so that is easier to understand and debug
if string.characters.contains(".") {
if string.componentsSeparatedByString(".").count > 2 {
return false
} else {
let newStringSplitAtDecimal = string.componentsSeparatedByString(".")
@sanketfirodiya
sanketfirodiya / gist:9fb6654fe8d757b2edd0
Created December 5, 2015 19:49
Give lldb superpowers
expr @import UIKit
# Uncrustify 0.61
#
# General options
#
# The type of line endings
newlines = auto # auto/lf/crlf/cr
# The original size of tabs in the input
@sanketfirodiya
sanketfirodiya / gist:3a955d685a0bba52c405
Created May 21, 2015 18:49
Determine the method callee
NSString *sourceString = [[NSThread callStackSymbols] objectAtIndex:1];
// Example: 1 UIKit 0x00540c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
NSCharacterSet *separatorSet = [NSCharacterSet characterSetWithCharactersInString:@" -[]+?.,"];
NSMutableArray *array = [NSMutableArray arrayWithArray:[sourceString componentsSeparatedByCharactersInSet:separatorSet]];
[array removeObject:@""];
NSLog(@"Stack = %@", [array objectAtIndex:0]);
NSLog(@"Framework = %@", [array objectAtIndex:1]);
NSLog(@"Memory address = %@", [array objectAtIndex:2]);
NSLog(@"Class caller = %@", [array objectAtIndex:3]);
+ (BOOL)isBSTValid {
return [self validate:self.root withMin:MIN.INTEGER withMax:MAX.INTEGER];
}
- (BOOL)validate:(Node *)root withMin:(NSUInteger)min withMax:(NSUInteger)max {
if (root.value <= min || root.value >= max) {
return NO;
}
@sanketfirodiya
sanketfirodiya / gist:3b7b9dfbbeb8bc97a30b
Last active April 26, 2016 06:51
Check if BST is balanced
- (BOOL)isBSTBalanced:(Node *)root {
return ([self maxHeight:root] - [self minHeight:root] <= 1);
}
- (NSUInteger)maxHeight:(Node *)root {
if (root == null) {
return 0;
}
return MAX([self maxHeight:root.leftNode], [self maxHeight:root.rightNode]) + 1;