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
@snowshoes
snowshoes / getTImeOfDay.swift
Last active November 24, 2022 05:04
[Format time of the day Swift]find a way to get time of the day in words #tags: swift, date, time
// http://stackoverflow.com/questions/32649039/formatting-time-of-the-day-swift-morning-afternoon-evening-any-time
// Same Principle as BigNerdRanch Silver Challenge
let hour = Calendar.currentCalendar().component(.Hour, fromDate: Date())
switch hour {
case 6..<12 : print(NSLocalizedString("Morning", comment: "Morning"))
case 12 : print(NSLocalizedString("Noon", comment: "Noon"))
case 13..<17 : print(NSLocalizedString("Afternoon", comment: "Afternoon"))
case 17..<22 : print(NSLocalizedString("Evening", comment: "Evening"))
default: print(NSLocalizedString("Night", comment: "Night"))
@MattSHallatt
MattSHallatt / DateComponentsFormatter.playground
Created November 30, 2017 15:06
DateComponentsFormatter Playground
import UIKit
/*:
DateComponentsFormatter: A formatter that creates string representations of quantities of time.
*/
let dateComponentsFormatter = DateComponentsFormatter()
/*:
A DateComponentsFormatter can be configured with an array of NSCalendarUnits. These components are then used in the output.
@pchelnikov
pchelnikov / URLRequest-debugging.swift
Last active December 8, 2023 11:16
URLRequest debugging
//Declare extension to URLRequest:
extension URLRequest {
public var curlString: String {
// Logging URL requests in whole may expose sensitive data,
// or open up possibility for getting access to your user data,
// so make sure to disable this feature for production builds!
#if !DEBUG
return ""
@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
@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;
@epaga
epaga / TappableView.swift
Last active December 13, 2021 17:57
SwiftUI View for getting taps with(!) the tap locations unlike the current tapAction and tapGestures of SwiftUI
// SwiftUI View for getting taps with(!) the tap locations unlike the current tapAction and tapGestures of SwiftUI
// There may be a way easier way to do this, not sure...
/*
Use like so:
TappableView {
(location, taps) in
if taps == 1 {
print("single tap at \(location)")
@ohayon
ohayon / DraggableView.swift
Last active April 5, 2023 16:24
Example of making a reusable `draggable()` modifier for SwiftUI Views
struct DraggablePita: View {
var body: some View {
Image(uiImage: UIImage(named: "pita.png")!)
.draggable() // Add the new, custom modifier to make this draggable
}
}
// Handle dragging
struct DraggableView: ViewModifier {
@State var offset = CGPoint(x: 0, y: 0)
@Amzd
Amzd / PreferenceUIHostingController.swift
Last active September 8, 2023 12:14
PreferenceUIHostingController. Adds hiding home indicator and deferring system edge gestures to SwiftUI. (Don't work at the same time but I think that's normal?)
extension View {
/// Controls the application's preferred home indicator auto-hiding when this view is shown.
func prefersHomeIndicatorAutoHidden(_ value: Bool) -> some View {
preference(key: PreferenceUIHostingController.PrefersHomeIndicatorAutoHiddenPreferenceKey.self, value: value)
}
/// Controls the application's preferred screen edges deferring system gestures when this view is shown. Default is UIRectEdgeNone.
func edgesDeferringSystemGestures(_ edge: UIRectEdge) -> some View {
preference(key: PreferenceUIHostingController.PreferredScreenEdgesDeferringSystemGesturesPreferenceKey.self, value: edge)
}
@chriseidhof
chriseidhof / script.swift
Last active February 21, 2023 05:12
SwiftUI
import SwiftSyntax
import SwiftSemantics
import Foundation
let source = try! String(contentsOf: URL(fileURLWithPath: "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/arm64e.swiftinterface"))
var collector = DeclarationCollector()
let tree = try SyntaxParser.parse(source: source)
tree.walk(&collector)
@mdiep
mdiep / diff-values.swift
Last active February 13, 2024 21:01
Diff values with Codable, CaseIterable, and KeyPaths
import Foundation
// Diff objects for better test assertions.
//
// Implemented in a way that:
// 1. The compiler generates as much code as possible
// 2. You'll get a compiler error if you forget a property
//
// Nested support and collections left as an exercise for the reader.