This file contains hidden or 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
| // | |
| // View+OpenUrl.swift | |
| // | |
| // Created by James Sedlacek on 11/26/24. | |
| // | |
| /// This file provides a safe way to open URLs in SwiftUI applications. | |
| /// It adds a view modifier that handles URL opening with user confirmation | |
| /// and multiple opening options (browser, in-app, or copy to clipboard). | |
| /// |
This file contains hidden or 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
| enum Status: Decodable { | |
| case completed, inProgress | |
| case other(String) | |
| init(from decoder: Decoder) throws { | |
| let container = try decoder.singleValueContainer() | |
| let value = try container.decode(String.self) | |
| switch value { | |
| case "completed": self = .completed |
This file contains hidden or 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
| /* | |
| These three methods can be used for making network calls less repetitive. Apple's example code for a basic | |
| network call is typically around 45 lines. Using these helper methods along with methods to build up each | |
| URL, most network calls can be completed in about 15 lines. | |
| */ | |
| private func perform(_ request: URLRequest, completion: @escaping (Result<Data, Error>) -> Void) { | |
| let dataTask = URLSession.shared.dataTask(with: request) { data, response, error in | |
| if let error = error { |
This file contains hidden or 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
| // | |
| // ShiftableViewController.swift | |
| // | |
| // Copyright © 2017 Spencer Curtis. All rights reserved. | |
| // | |
| /* | |
| All you need to do is set your subclass of ShiftableViewController as the delegate for all | |
| UITextFields and UITextViews that you want to be shifted up so the keyboard doesn't obscure it. |
This file contains hidden or 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 flipMatrix(_ A: [[Int]]) -> [[Int]] { | |
| var flipped: [[Int]] = [] | |
| for i in 0..<A[0].count { | |
| flipped.append(contentsOf: [[]]) | |
| for j in 0..<A.count { | |
| flipped[i].append(A[j][i]) | |
| } | |
| } | |
| return flipped |
This file contains hidden or 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 | |
| func findDisappearedNumbers(_ nums: [Int]) -> [Int] { | |
| var missingNumbers: [Int] = [] | |
| let sortedNumbers = Array(Set(nums).sorted()) | |
| for number in 1..<sortedNumbers[0] { | |
| missingNumbers.append(number) | |
| } |
This file contains hidden or 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 sum(_ nums: [Int], _ target: Int) -> [Int] { | |
| var first = 0 | |
| var second = 1 | |
| for i in 0...nums.count - 1 { | |
| for j in i + 1...nums.count - 1 { | |
| if nums[i] + nums[j] == target { | |
| first = i | |
| second = j | |
| return [i, j] | |
| } |
This file contains hidden or 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 fizzBuzz(_ n: Int) -> [String] { | |
| if n == 0 { | |
| return [] | |
| } | |
| var start: Int { | |
| if n >= 1 { return 1 } | |
| else if n < 0 { return n } | |
| else { return 0 } | |
| } |
This file contains hidden or 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 arr1 = [2,3,1,3,2,4,6,7,9,2,19] | |
| let arr2 = [2,1,4,3,9,6] | |
| func order(_ array1: [Int], by array2: [Int]) -> [Int] { | |
| var array1 = array1 | |
| var endingArray: [Int] = [] | |
| var workingArray: [Int] = [] | |
| for number in array2 { | |
| workingArray = array1.filter { $0 == number } |
This file contains hidden or 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 heightChecker(_ heights: [Int]) -> Int { | |
| let sortedHeights = heights.sorted() | |
| var moveCount = 0 | |
| for i in 0..<heights.count { | |
| if sortedHeights[i] != heights[i] { | |
| moveCount += 1 | |
| } | |
| } |
NewerOlder