Skip to content

Instantly share code, notes, and snippets.

View aniltv06's full-sized avatar

Anil T V aniltv06

View GitHub Profile
func fetchCount(array: [Int], length: Int, symmetric: Bool) -> Int {
var count = 0
for index in array.indices where index + length < array.count {
let subArray = array[index..<(index + length)]
print("Sub-array \"\(subArray)\" is \(subArray.allEqual() == true ? "Symmetrical" : "Asymmetrical")")
if symmetric == subArray.allEqual() {
count = count + 1
}
}
@aniltv06
aniltv06 / alert.swift
Created March 30, 2018 06:41
UIAlertController with text field and disable buttons if textfield is empty
let alertController = UIAlertController(title: nil, message: alertMessageString, preferredStyle: .alert)
let cancelAction = UIAlertAction(title: alertLeftBtuTitle, style: .default, handler: nil)
alertController.addAction(cancelAction)
let okAction = UIAlertAction(title: alertRightBtnText , style: UIAlertActionStyle.default, handler: {
(action) -> Void in
print("ok tapped")
})
okAction.isEnabled = false
alertController.addAction(okAction)
@aniltv06
aniltv06 / alertSheet.swift
Last active September 29, 2016 09:33
Alert Sheet Code in Swift 3
let alert = NSAlert()
alert.messageText = "Enter Message"
alert.informativeText = "Enter Informative Message"
alert.alertStyle = NSInformationalAlertStyle
alert.addButton(withTitle: "OK")
alert.addButton(withTitle: "Cancel")
alert.beginSheetModal(for: self.window, completionHandler: { (modalResponse) in
if(modalResponse == NSAlertFirstButtonReturn){
@aniltv06
aniltv06 / Label.swift
Created September 12, 2016 13:10
Adding UILabel programatically in Swift 3
class ViewController: UIViewController {
var label : UILabel! = nil
override func viewDidLoad() {
super.viewDidLoad()
self.label = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 21))
self.label.font = UIFont.preferredFont(forTextStyle: .footnote)
self.label.textColor = .black
self.label.center = CGPoint(x: 200, y: 300)
@aniltv06
aniltv06 / compressBytes.h
Created September 12, 2016 06:23
Compress the passed chunk of data
@interface compressBytes : NSObject {
z_stream zStream;
}
- (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err shouldFinish:(BOOL)shouldFinish;
@aniltv06
aniltv06 / TimerClass.swift
Created September 8, 2016 10:01
Add NSTimer in swift
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
_ = NSTimer.scheduledTimerWithTimeInterval(1.0/30.0, target: self, selector: #selector(ViewController.methodName), userInfo: nil, repeats: true)
}
func methodName(){
print("Method Called")
}
}
@aniltv06
aniltv06 / Singleton.swift
Created September 7, 2016 07:46
Singleton
import Foundation
class Singleton {
class var sharedInstance: Singleton {
struct Static {
static var onceToken: dispatch_once_t = 0
static var instance: Singleton? = nil
}
dispatch_once(&Static.onceToken) {
Static.instance = Singleton()
@aniltv06
aniltv06 / UILabelStrikethrough.h
Created September 20, 2011 05:15 — forked from mikaelbartlett/UILabelStrikethrough.h
Simple class for IOS SDK UILabel with strikethrough
@interface UILabelStrikethrough : UILabel {
int xOffset;
int yOffset;
int widthOffset;
int stroke;
UIColor* strokeColor;
}
@property (nonatomic) int xOffset;
@property (nonatomic) int yOffset;
@property (nonatomic) int widthOffset;