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
// The SwiftUI Lab | |
// Website: https://swiftui-lab.com | |
// Article: https://swiftui-lab.com/alignment-guides | |
import SwiftUI | |
class Model: ObservableObject { | |
@Published var minimumContainer = true | |
@Published var extendedTouchBar = false | |
@Published var twoPhases = true |
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
extension String { | |
var length: Int { | |
return count | |
} | |
subscript (i: Int) -> String { | |
return self[i ..< i + 1] | |
} | |
func substring(fromIndex: Int) -> String { | |
return self[min(fromIndex, length) ..< length] | |
} |
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
extension NSNotification.Name { | |
public static let deviceDidShakeNotification = NSNotification.Name("MyDeviceDidShakeNotification") | |
} | |
extension UIWindow { | |
open override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) { | |
super.motionEnded(motion, with: event) | |
NotificationCenter.default.post(name: .deviceDidShakeNotification, object: event) | |
} | |
} | |
extension View { |
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 Show: ViewModifier { | |
let isVisible: Bool | |
@ViewBuilder | |
func body(content: Content) -> some View { | |
if isVisible { | |
content | |
} else { | |
content.hidden() | |
} |
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
extension URL { | |
func loadImage(_ image: inout UIImage) { | |
if let loaded = UIImage(contentsOfFile: self.path) { | |
image = loaded | |
} | |
} | |
func saveImage(_ image: UIImage) { | |
if let data = image.jpegData(compressionQuality: 1.0) { | |
try? data.write(to: self) | |
} |
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 returnSize: View { | |
var color: Color = .clear | |
var body: some View { | |
GeometryReader { geometry in | |
color | |
.onAppear(perform: { | |
print("returnSize: \(geometry.size)") | |
}) | |
} | |
} |