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
let regex3 = Regex { | |
"a" | |
Capture { | |
OneOrMore(.word) | |
} | |
" " | |
} | |
let match3 = baseString.firstMatch(of: regex3) | |
print(match3?.1) |
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
let regex2 = /a(?<remainder>.*?)\ / | |
let match2 = baseString.firstMatch(of: regex2) | |
print(match2?.remainder) |
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
let baseString = "An anchor or an anchorman, take your pick" | |
let regex = try Regex("a(.*) ") | |
let match = baseString.firstMatch(of: regex) | |
print(match?.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
let endpoint = "https://OBTAINED-FROM-DASHBOARD.azconfig.io" | |
let secret = "PASTE-SECRET-HERE" | |
let credential = "PASTE-CREDENTIAL-HERE" | |
// Fetch and decode the configuration | |
let request = try AzureAppConfiguration.prepareRequest(endpoint: endpoint, secret: secret, credential: credential) | |
let (data, _) = try await URLSession.shared.data(for: request) | |
let dictionary = try AzureAppConfiguration.decodeResponse(data: data) |
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
{ | |
"items": [ | |
{ | |
"etag": "A3uJKGd9vCNHpUzaDAMPiAFrZUK", | |
"key": "AndroidRequiredVersion", | |
"label": null, | |
"content_type": "", | |
"value": "2.1", | |
"tags": {}, | |
"locked": false, |
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
// Set the Date header to our Date as a UTC String. | |
const dateStr = new Date().toUTCString(); | |
pm.request.headers.upsert({key:'Date', value: dateStr}); | |
// Hash the request body using SHA256 and encode it as Base64 | |
const hashedBodyStr = CryptoJS.SHA256(pm.request.body.raw).toString(CryptoJS.enc.Base64) | |
// And add that to the header x-ms-content-sha256 | |
pm.request.headers.upsert({ | |
key:'x-ms-content-sha256', | |
value: hashedBodyStr |
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 XCTest | |
@testable import AsyncAwaitModule | |
class AsyncAwaitModuleTests: XCTestCase { | |
// note the complexity in this unit test | |
func testClosure() throws { | |
let expectation = expectation(description: "posts fetch") | |
PostsService().fetchPosts { result in |
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 Foundation | |
import UIKit | |
enum PostError: Error { | |
case badURL | |
case badResponse | |
case noData | |
case decodingError | |
} |
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
let sub = NotificationCenter.default | |
.publisher(for: NSControl.textDidChangeNotification, object: filterField) | |
.map( { ($0.object as! NSTextField).stringValue } ) | |
.filter( { $0.unicodeScalars.allSatisfy({CharacterSet.alphanumerics.contains($0)}) } ) | |
.debounce(for: .milliseconds(500), scheduler: RunLoop.main) | |
.receive(on: RunLoop.main) | |
.assign(to:\MyViewModel.filterString, on: myViewModel) |
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
func useAsynchronousFetch() -> Void { | |
fetchData(value: 23) { result in | |
switch result { | |
case .success(let data): | |
transformData(data) { result in | |
switch result { | |
case .success(let viewModel): | |
displayModel(viewModel) | |
case .failure(let error): | |
displayError(error) |
NewerOlder