Skip to content

Instantly share code, notes, and snippets.

@azuredark
azuredark / sort_methods.swift
Created August 23, 2022 08:25 — forked from NoemiRozpara/sort_methods.swift
Few methods of sorting implemented in swift
// O(n2)
func selectionSort(array: [Int]) -> [Int] {
var copy = array
for index in 0..<copy.count - 1 {
let subarray = copy.suffix(from: index + 1)
let min = subarray.min()!
if min < copy[index] {
let indexOfMin = subarray.firstIndex(of: min)!
@azuredark
azuredark / MainStoryboard.storyboard
Created August 23, 2022 08:26 — forked from ahmattox/MainStoryboard.storyboard
UITableView Sorting with Animations
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="3084" systemVersion="12C60" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="2">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="2083"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="5">
<objects>
<viewController id="2" customClass="TTViewController" sceneMemberID="viewController">
@azuredark
azuredark / 1.CustomClass.h
Created November 14, 2022 02:33 — forked from lamprosg/1.CustomClass.h
(iOS) Creating custom delegates
//Class will be declared later
@class CustomClass;
//Define the protocol for the delegate
@protocol CustomClassDelegate
@required
//Required methods go here
//If there are optional functions, they go here
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
guard let headerView = tableView.tableHeaderView else {
return
}
// The table view header is created with the frame size set in
// the Storyboard. Calculate the new size and reset the header
// view to trigger the layout.
@azuredark
azuredark / httpRequest.m
Created November 25, 2022 01:31 — forked from pbakondy/httpRequest.m
HTTP Request Objective-C implementations
#import <Foundation/Foundation.h>
@interface MyNetwork : NSObject
- (NSData* )httpRequestWithURL:(NSURL *)url httpMethod:(NSString *)httpMethod body:(NSData *)body contentType:(NSString *)contentType error:(NSError **)error;
@end
@implementation MyNetwork
@azuredark
azuredark / DataPassing.swift
Created December 23, 2022 01:38 — forked from AghaShahriyar/DataPassing.swift
Passing data between ViewControllers using closure in swift
//Passing Data Between ViewControllers Using Closure
//In this model, i am considering two viewController i-e PresentViewController and ParentViewController. Closure is used to pass the data from PresentVC to ParentVC after the dismiss of PersentVC.
//PresentViewController
//Declaration of closure and assigning to completionHandler
typealias sourceClosure = ((_ source: DataModel?) -> Void)
var sourceCompletionHandler: sourceClosure?
@azuredark
azuredark / MVVMPlayground.swift
Created April 19, 2023 15:00 — forked from crenwick/MVVMPlayground.swift
MVVM-ProtocolOriented
import UIKit
///////////////
// View Cell //
///////////////
protocol SwitchWithTextCellDataSource {
var title: String { get }
var switchOn: Bool { get }
}
@azuredark
azuredark / SortedTableView.swift
Created May 10, 2023 23:56 — forked from 128keaton/SortedTableView.swift
Sorting a UITableView by a NSDate object with headers in Swift
extension NSDate{
convenience
init(inputDate: NSDate){
let calendar = NSCalendar.currentCalendar()
let timeZone = NSTimeZone.systemTimeZone()
calendar.timeZone = timeZone
let comps = calendar.components([NSCalendarUnit.Year, NSCalendarUnit.Month, NSCalendarUnit.Day ], fromDate: inputDate)
comps.hour = 0
comps.minute = 0
comps.second = 0
@azuredark
azuredark / PageViewControllerSegmentedAdapter.swift
Created June 1, 2023 21:22 — forked from dchohfi/PageViewControllerSegmentedAdapter.swift
Connect UISegmentControll to UIPageViewController
import UIKit
final class PageViewControllerSegmentedAdapter: NSObject {
private let pageViewController: UIPageViewController
fileprivate let segmentControl: UISegmentedControl
fileprivate let viewControllers: [UIViewController]
fileprivate var selectedIndex: Int = 0
init(pageViewController: UIPageViewController, segmentControl: UISegmentedControl, viewControllers: [UIViewController]) {
@azuredark
azuredark / EmployeeApiService.swift
Created June 1, 2023 23:59 — forked from seyhunak/EmployeeApiService.swift
Swift 5 - MVVM - ViewController, ViewModel, Model, Datasource, Webservice
import Foundation
class APIService : NSObject {
private let sourcesURL = URL(string: "http://dummy.restapiexample.com/api/v1/employees")!
func apiToGetEmployeeData(completion : @escaping (Employees) -> ()){
URLSession.shared.dataTask(with: sourcesURL) { (data, urlResponse, error) in
if let data = data {
let jsonDecoder = JSONDecoder()
let empData = try! jsonDecoder.decode(Employees.self, from: data)