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
// Support iOS 14+ | |
func getNetworkConnectionType() -> String { | |
var connectionType: String = "Unknown" | |
let networkInfo = CTTelephonyNetworkInfo() | |
let carrierType = networkInfo.serviceCurrentRadioAccessTechnology | |
guard let carrierTypeName = carrierType?.first?.value else { | |
return connectionType |
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
Universal link testing from terminal | |
xcrun simctl openurl booted “https://www.way.com/parkingdetails/1579270/Holiday-Inn-San-Francisco-SFO-Airport-Parking” |
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
//Initialization | |
var userDefaultsCustom: UserDefaults? | |
let userDefaultsSuiteName = "UserStateManagerTests" //You can pass class name here. | |
// In setUp() method | |
UserDefaults().removePersistentDomain(forName: userDefaultsSuiteName) | |
userDefaultsCustom = UserDefaults(suiteName: userDefaultsSuiteName) | |
// In test cases methods. | |
userDefaultsCustom?.setValue("SomeRandomValue", forKey: "SomeRandomKey") |
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
//Without using generics | |
struct StackEx { | |
private var items: [Any] = [] | |
mutating func push(item: Any) { items.append(item) } | |
mutating func pop() -> Any { items.popLast() as Any } | |
var top: Any { return items.last as Any } | |
mutating func getAll() -> [Any] { return items } | |
} | |
var stacktEx = StackEx() |
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
/// Get the app document direcitory path | |
/// - Returns: path as URL | |
func getDocumentsDirectory() -> URL { | |
// Find all possible documents directories for this user | |
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) | |
// just send back the first one, Usually it will be only one | |
return paths[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
extension String { | |
/// Method to check whether the string has only characters. | |
/// - Returns: bool value. | |
func isNumber() -> Bool { | |
return !isEmpty && rangeOfCharacter(from: CharacterSet.decimalDigits.inverted) == nil | |
} | |
/// Method to validate email address string | |
/// - Returns: BOOL |
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 parse(jsonData: Data) -> sampleRecord? { | |
do { | |
let decodedData = try JSONDecoder().decode(sampleRecord.self, from: jsonData) | |
return decodedData | |
} catch { | |
print("error: \(error)") | |
} | |
return nil | |
} |
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 readLocalJSONFile(forName name: String) -> Data? { | |
do { | |
if let filePath = Bundle.main.path(forResource: name, ofType: "json") { | |
let fileUrl = URL(fileURLWithPath: filePath) | |
let data = try Data(contentsOf: fileUrl) | |
return data | |
} | |
} catch { | |
print("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
import XCTest | |
// Sample class with one method in it. | |
class evenOddClass { | |
func isEvenNumber(_ number: Int) -> Bool { | |
if number % 2 == 0 { | |
return true | |
} else { | |
return false |
NewerOlder