This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns black if the given background color is light or white if the given color is dark | |
func textColor(bgColor: UIColor) -> UIColor { | |
var r: CGFloat = 0.0 | |
var g: CGFloat = 0.0 | |
var b: CGFloat = 0.0 | |
var a: CGFloat = 0.0 | |
var brightness: CGFloat = 0.0 | |
bgColor.getRed(&r, green: &g, blue: &b, alpha: &a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension Spacer { | |
static func maxHeight(_ value: CGFloat) -> some View { | |
Spacer(minLength: 0) | |
.frame(maxHeight: value) | |
.layoutPriority(-1) | |
} | |
static func maxWidth(_ value: CGFloat) -> some View { | |
Spacer(minLength: 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TranslucentTitleBarApp.swift | |
// TranslucentTitleBar | |
// | |
// Created by Alexander Sandberg on 20.10.22. | |
// | |
import SwiftUI | |
@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// XCode 4.2.1 | |
@implementation NSString(EmojiExtension) | |
- (NSString*)removeEmoji { | |
__block NSMutableString* temp = [NSMutableString string]; | |
[self enumerateSubstringsInRange: NSMakeRange(0, [self length]) options:NSStringEnumerationByComposedCharacterSequences usingBlock: | |
^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct AttributesOf<Object>: CustomStringConvertible { | |
enum Error: Swift.Error { case message(String) } | |
public typealias Assignment = (keyPath: AnyKeyPath, set: (Object) -> Void) | |
private(set) var assignments: [Assignment] | |
init(@AttributesOfBuilder<Object> _ builder: () throws -> [Assignment]) rethrows { | |
assignments = try builder() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Taken from Apple's App Dev Training: https://developer.apple.com/tutorials/app-dev-training/ | |
/// This color is either black or white, whichever is more accessible when viewed against the scrum color. | |
var accessibleFontColor: Color { | |
var red: CGFloat = 0 | |
var green: CGFloat = 0 | |
var blue: CGFloat = 0 | |
UIColor(self).getRed(&red, green: &green, blue: &blue, alpha: nil) | |
return isLightColor(red: red, green: green, blue: blue) ? .black : .white | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |