Skip to content

Instantly share code, notes, and snippets.

View gopalkrishnareddy's full-sized avatar

Gopal Krishna Reddy Thotli gopalkrishnareddy

  • Harman India
  • Bangalore
View GitHub Profile
@gopalkrishnareddy
gopalkrishnareddy / minimal.swift
Created October 17, 2017 09:50 — forked from sjoerdvisscher/minimal.swift
Using Decodable to generate a minimal value
struct MinimalDecoder : Decoder {
var codingPath = [CodingKey?]()
var userInfo = [CodingUserInfoKey : Any]()
public func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
return KeyedDecodingContainer(MinimalKeyedDecodingContainer<Key>(decoder: self))
}
public func unkeyedContainer() throws -> UnkeyedDecodingContainer {
return DecodingContainer(decoder: self)

Using Swift Package Manager with iOS

Step 1:

File > New > Project...

Step 2:

Create a Package.swift file in your root project directory, add dependencies, then run swift package fetch on the command line in the same directory. We’re not going to run swift build because it will just complain.

@gopalkrishnareddy
gopalkrishnareddy / MyImageDownloader.h
Created May 18, 2018 06:30 — forked from oliverfoggin/MyImageDownloader.h
NSURLConnection download with progress callbacks
@protocol MyImageDownloaderDelegate <NSObject>
- (void)downloadFailed;
- (void)imageDownloadFinished:(UIImage *)image;
- (void)progressUpdated:(CGFloat)progress;
@end
@interface MyImageDownloader : NSObject
@gopalkrishnareddy
gopalkrishnareddy / universal-framework.sh
Created September 28, 2018 11:10 — forked from cromandini/universal-framework.sh
This run script will build the iphoneos and iphonesimulator schemes and then combine them into a single framework using the lipo tool (including all the Swift module architectures).
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
@gopalkrishnareddy
gopalkrishnareddy / universal-framework.sh
Created September 28, 2018 11:10 — forked from Tokuriku/universal-framework.sh
Script to put in an Aggregate Target of a Framework in Xcode 6 to create a Universal Framework
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
extension UITextView {
func hideSuggestions() {
// Removes suggestions only
autocorrectionType = .no
//Removes Undo, Redo, Copy & Paste options
removeUndoRedoOptions()
}
}
extension UITextField {
@gopalkrishnareddy
gopalkrishnareddy / UIWebView+Additions.h
Created March 14, 2019 08:08 — forked from akisute/UIWebView+Additions.h
UIWebView addition to enable/disable scrolling
#import <UIKit/UIKit.h>
@interface UIWebView (Additions)
/*!
@abstract Enable/Disable the receiver from scrolling.
*/
@property (nonatomic, assign) BOOL webViewScrollEnabled;
@gopalkrishnareddy
gopalkrishnareddy / externalKeyboard.m
Created May 10, 2019 16:45 — forked from myell0w/externalKeyboard.m
Detect if there's an external keyboard attached (iOS)
// direct check for external keyboard
+ (BOOL)_isExternalKeyboardAttached
{
BOOL externalKeyboardAttached = NO;
@try {
NSString *keyboardClassName = [@[@"UI", @"Key", @"boa", @"rd", @"Im", @"pl"] componentsJoinedByString:@""];
Class c = NSClassFromString(keyboardClassName);
SEL sharedInstanceSEL = NSSelectorFromString(@"sharedInstance");
if (c == Nil || ![c respondsToSelector:sharedInstanceSEL]) {
@gopalkrishnareddy
gopalkrishnareddy / HWKViewController.m
Created May 10, 2019 16:52 — forked from steventroughtonsmith/HWKViewController.m
Example of dynamic iOS UI that changes based on the connection/disconnection of a hardware keyboard, based on suggestions from @JohnRHeaton. Requires linking to private GraphicsServices framework. rdar://problem/15447952
//
// HWKViewController.m
// HardwareKeyboardUI
//
// Created by Steven Troughton-Smith on 13/11/2013.
// Copyright (c) 2013 High Caffeine Content. All rights reserved.
//
#import "HWKViewController.h"
@gopalkrishnareddy
gopalkrishnareddy / Locale+TimeFormat.swift
Last active August 6, 2020 09:09
Swift - iOS Device Time Format - 12 Hour or 24 Hour
extension Locale {
static func is12HoursFormat() -> Bool {
DateFormatter.dateFormat(fromTemplate: "j", options: 0, locale: Locale.current)?.range(of: "a") != nil
}
static func is24HoursFormat() -> Bool {
!Self.is12HoursFormat()
}
func is12HoursFormat() -> Bool {