Skip to content

Instantly share code, notes, and snippets.

View JayachandraA's full-sized avatar
🎯
Focusing

Jayachandra Agraharam JayachandraA

🎯
Focusing
View GitHub Profile
struct AssociatedKeys {
static var placeholderColor: String = "placeholderColor"
}
var placeholderColor: UIColor? {
set {
objc_setAssociatedObject(self, &AssociatedKeys.placeholderColor, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
}
get {
struct Instance {
static var floating: Bool = false
}
var floating: Bool{
set{
Instance.floating = newValue
}
@JayachandraA
JayachandraA / add_keyboard_notification_observers.swift
Created September 18, 2018 13:34
How to handle the keyboard show and hide animation in iOS
NotificationCenter.default.addObserver(self, selector: #selector(self.handleKeyboard), name: .UIKeyboardWillHide, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.handleKeyboard), name: .UIKeyboardWillShow, object: nil)
First just enable battery monitoring:
UIDevice.current.isBatteryMonitoringEnabled = true
Then you can create a computed property to return the battery level:
var batteryLevel: Float {
return UIDevice.current.batteryLevel
}
To monitor your device battery level you can add an observer for the UIDeviceBatteryLevelDidChange notification:
@JayachandraA
JayachandraA / fix-homebrew-owner-perms.sh
Created June 29, 2018 10:21 — forked from stefanschmidt/fix-homebrew-owner-perms.sh
Fix ownership and permissions of a multi-user Homebrew installation
# fix owner of files and folders recursively
sudo chown -vR $(whoami) /usr/local /opt/homebrew-cask /Library/Caches/Homebrew
# fix read/write permission of files and folders recursively
chmod -vR ug+rw /usr/local /opt/homebrew-cask /Library/Caches/Homebrew
# fix execute permission of folders recursively
find /usr/local /opt/homebrew-cask /Library/Caches/Homebrew -type d -exec chmod -v ug+x {} +
@JayachandraA
JayachandraA / difference_between_struct_class.swift
Last active April 5, 2018 07:29
Difference between struct and class in swift4.0
//finding memory location of stack and heap
func addressHeap<T: AnyObject>(o: T) -> Int {
return unsafeBitCast(o, to: Int.self)
}
func addressStack(o: UnsafeRawPointer) -> Int {
return Int(bitPattern: o)
}
//structure is a value based
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
{
NSMutableArray *data;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
NSString *assetLocalPath = [[NSBundle mainBundle] pathForResource:@"AnimatedSplashScreen" ofType:@"gif"];
NSURL *assetURL = [[NSURL alloc] initFileURLWithPath:assetLocalPath];
//add the image to the forefront...
@JayachandraA
JayachandraA / employee.json
Created September 19, 2017 09:56
A sample json file
{ "employees": [
{
"createdAt": "2015-07-18T19:41:01.125Z",
"department": "Marketing",
"email": "louis.campbell@example.com",
"name": "Louis Campbell",
"objectId": "1xnwPwwWVk",
"phone": "(517)-516-9601",
"skills": [
"html",
@JayachandraA
JayachandraA / time-falls-between-two-dates.m
Created September 12, 2017 17:06
time-falls-between-two-dates
- (BOOL)isTimeFallsBetweenTwoDates:(NSDate*)start another:(NSDate*)end{
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *openingTime = [gregorian components:(NSCalendarUnitHour |
NSCalendarUnitMinute) fromDate:start];
NSDateComponents *closingTime = [gregorian components:(NSCalendarUnitHour |
NSCalendarUnitMinute) fromDate:end];
NSDate *now = [NSDate date];