Contents:
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
- (NSImage *)imageWithColorOverlay:(NSColor *)color { | |
CGFloat scale = [self recommendedLayerContentsScale:[[NSScreen mainScreen] backingScaleFactor]]; | |
NSImage * overlayedImage = [[NSImage alloc] initWithSize:self.size]; | |
[self.representations enumerateObjectsUsingBlock:^(NSImageRep * imageRep, NSUInteger idx, BOOL *stop){ | |
CGFloat imageWidth = imageRep.pixelsWide ?: imageRep.size.width * scale; | |
CGFloat imageHeight = imageRep.pixelsHigh ?: imageRep.size.height * scale; | |
NSRect imageRect = NSMakeRect(0, 0, imageWidth, imageHeight); |
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 UIKit | |
enum MensSize { | |
case S | |
case M | |
case L | |
case XL | |
} | |
var size = MensSize.M |
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 UIKit | |
import LocalAuthentication | |
func requestFingerprintAuthentication() { | |
let context = LAContext() | |
var authError: NSError? | |
let authenticationReason: String = "To display a message to the user" | |
if context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &authError) { | |
context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: authenticationReason, reply: { |
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 Data { | |
public func apnsToken() -> String { | |
var token: String = "" | |
for i in 0 ..< self.count { | |
token += String(format: "%02.2hhx", self[i] as CVarArg) | |
} | |
return token |
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 { | |
func isValidEmail() -> Bool { | |
let regex = try? NSRegularExpression(pattern: "^(((([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+(\\.([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|\\.|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.)+(([a-zA-Z |
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
class ViewController: UIViewController { | |
var sampleImageURLs = ["https://yesofcorsa.com/wp-content/uploads/2016/12/4K-Black-Wallpaper-UHD.jpg","https://images.unsplash.com/photo-1551509134-2f9d4ec80a9b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjI0MX0&auto=format&fit=crop&w=1650&q=80","https://i.picsum.photos/id/885/200/300.jpg?grayscale"] | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
checkDispatchGroup() | |
checkDispatchSemaphor() | |
} |
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
@main | |
struct SwiftUIAppLifeCycle: App { | |
@Environment(\.scenePhase) var scenePhase | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
} | |
.onChange(of: scenePhase) { newScenePhase in | |
switch newScenePhase { |
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 SwiftUI | |
struct ContentView: View { | |
@State private var logoImage: UIImage? | |
var body: some View { | |
Image(uiImage: logoImage ?? UIImage()) | |
.resizable() |
OlderNewer