Skip to content

Instantly share code, notes, and snippets.

@Dexwell
Dexwell / LocalCommunicationNotification.swift
Last active April 2, 2024 07:44
iOS 15 Local Communication Notification
var content = UNMutableNotificationContent()
content.title = "Title"
content.subtitle = "Subtitle"
content.body = "Text"
content.sound = nil
content.categoryIdentifier = "categoryName"
var personNameComponents = PersonNameComponents()
personNameComponents.nickname = "Sender Name"
@timothycosta
timothycosta / SwiftUIKeyboardAnimation.swift
Last active May 15, 2024 13:19
Create a SwiftUI Animation with the correct curve and duration from UIKit keyboard notifications
func animation(from notification: Notification) -> Animation? {
guard
let info = notification.userInfo,
let duration = info[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double,
let curveValue = info[UIResponder.keyboardAnimationCurveUserInfoKey] as? Int,
let uiKitCurve = UIView.AnimationCurve(rawValue: curveValue)
else {
return nil
}
/// An animatable modifier that is used for observing animations for a given animatable value.
struct AnimationCompletionObserverModifier<Value>: AnimatableModifier where Value: VectorArithmetic {
/// While animating, SwiftUI changes the old input value to the new target value using this property. This value is set to the old value until the animation completes.
var animatableData: Value {
didSet {
notifyCompletionIfFinished()
}
}
@mishimay
mishimay / MyScrollView.swift
Created July 15, 2019 05:50
Bridge UIScrollView to SwiftUI
struct MyScrollView: UIViewRepresentable {
let swiftUIView: AnyView
func makeUIView(context: UIViewRepresentableContext<ContentView.MyScrollView>) -> UIView {
let hosting = UIHostingController(rootView: swiftUIView)
let width = UIScreen.main.bounds.width
let size = hosting.view.sizeThatFits(CGSize(width: width, height: CGFloat.greatestFiniteMagnitude))
hosting.view.frame = CGRect(x: 0, y: 0, width: width, height: size.height)
let view = UIScrollView()
view.alwaysBounceVertical = true
@zacwest
zacwest / ios-font-sizes.swift
Last active May 17, 2024 10:24
iOS default font sizes - also available on https://www.iosfontsizes.com
let styles: [UIFont.TextStyle] = [
// iOS 17
.extraLargeTitle, .extraLargeTitle2,
// iOS 11
.largeTitle,
// iOS 9
.title1, .title2, .title3, .callout,
// iOS 7
.headline, .subheadline, .body, .footnote, .caption1, .caption2,
]
@einfallstoll
einfallstoll / README.md
Created June 30, 2015 13:30
Reset Spotlight Location (Fix for OS X 10.11 El Capitan)

Installation for GUI Users

  1. Right click the file and choose information and choose to always open this file with Terminal.app

  2. Go to the Terminal.app and do something like this chmod 744 Reset Spotlight.sh

  3. There you go, you can now double click it so reset the Spotlight location

  4. Optional: Uncomment line for the useCount to prevent Spotlight to forget that you already used it

@SpacyRicochet
SpacyRicochet / Person.h
Last active January 3, 2016 09:29
Instead of overriding class initializers, consider overriding the new methods. There's only one default 'new' method, which makes autocompletion of your own custom ones a lot easier.
/** A person, with a name. */
@interface Person : NSObject
/** Creates a new person with the specified name. */
+ (id)newWithString:(NSString *)name;
@end
@mbinna
mbinna / podforceupdate.sh
Created December 4, 2012 09:43
Clear CocoaPods cache, re-download and re-install all pods
#!/usr/bin/env bash
rm -rf "${HOME}/Library/Caches/CocoaPods"
rm -rf "`pwd`/Pods/"
pod update
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@twe4ked
twe4ked / input.scss
Created December 5, 2011 06:27
FREE! Sass (SCSS) mixin for including retina images (useful when developing for iOS).
@mixin background-image-retina($file, $type, $width, $height) {
background-image: url($file + '.' + $type);
@media (-webkit-min-device-pixel-ratio: 2), (-moz-min-device-pixel-ratio: 2) {
& {
background-image: url($file + '@2x.' + $type);
-webkit-background-size: $width $height;
}
}
}