Skip to content

Instantly share code, notes, and snippets.

@ixcoder001
ixcoder001 / GenericFunc_SumMatch
Last active December 30, 2020 10:54
Generic Functions - Get List of Elements or List of Element Indexes that matches a Sum
func getListOfElementsThatMatchesSum<T: Numeric>(list: [T], sumMatches sum: T) -> [(T,T)] {
var result: [(T,T)] = []
for xIndex in 0..<list.count {
for yIndex in xIndex..<list.count {
if list[xIndex] + list[yIndex] == sum && xIndex != yIndex {
result.append((list[xIndex],list[yIndex]))
}
}
}
@ixcoder001
ixcoder001 / PWHighOrderFunctions.swift
Created December 13, 2020 15:17
Higher Order Functions - Swift
/**
HigherOrder Functions
1. Sort
2. Map
3. Reduce
4. Filter
What is Function?
Functions are self-contained chunks of code that perform a specific task. Function name should give clarity that what it does, and that name is used to “call” the function to perform its task when neede
@ixcoder001
ixcoder001 / PWEnum.swift
Created December 11, 2020 15:02
Enum (Enumeration) - Swift Programming - iOS
/**
An enumeration defines a common type for a group of related values and enables you to work with those values in a type-safe way within your code.
Enumerations in Swift are much more flexible, and don’t have to provide a value for each case of the enumeration.
Swift enumeration cases don’t have an integer value set by default, unlike languages like C and Objective-C. Enum cases don’t implicitly equal 0, 1, 2 and 3. Instead, the different enumeration cases are values in their own right, with an explicitly defined type of Enum Defined.
Enumerations in Swift are first-class types.
They adopt many features traditionally supported only by classes, such as
1. computed properties to provide additional information about the enumeration’s current value, and
@ixcoder001
ixcoder001 / PWGCD.swift
Created December 11, 2020 11:17
Using DispatchGroup - Handling Multiple API Calls And Perform Specific Action once All APIs are done - Swift Programming
/**
DispatchGroup:
You attach multiple work items to a group and schedule them for asynchronous execution on the same queue or different queues. When all work items finish executing, the group executes its completion handler.
You can also wait synchronously for all tasks in the group to finish executing.
DispatchGroup instance - Creates a new group to which you can assign block objects.
Functions:
enter() - Explicitly indicates that a block has entered the group.