Skip to content

Instantly share code, notes, and snippets.

//
// ViewFactory.swift
// FetchingView
//
// Created by NeilsUltimateLab.
//
import UIKit
public class ViewFactory {
static func postResource<A>(_ resource: WebResource<A>, completion: @escaping (Result<A>)->Void, progressCompletion: ((Double)->Void)?) {
guard let url = resource.urlPath.url else {
return
}
let parameter = resource.method.parameter
let header = resource.header
guard isReachable else {
UIApplication.shared.isNetworkActivityIndicatorVisible = false
@NeilsUltimateLab
NeilsUltimateLab / Initials.swift
Last active September 3, 2018 14:21
Find String Initials separated by space.
import Foundation
extension String {
var initials: String {
let split = self
.split(separator: " ")
.prefix(2)
.compactMap { $0.first }
.compactMap { String($0).uppercased() }
@NeilsUltimateLab
NeilsUltimateLab / Filepath.txt
Created October 2, 2018 18:22
XMPPFramework iOS Demo project
https://drive.google.com/file/d/14fHWSzV9FSZvo8nkFyrjQU2a3V5bKv0u/view
@NeilsUltimateLab
NeilsUltimateLab / ReusableView.swift
Created February 2, 2019 05:41
Typesafe wrapper for UITableView/UICollectionView cell registering.
import UIKit
protocol ReusableView: class {
static var reuseIdentifier: String { get }
}
extension ReusableView where Self: UIView {
static var reuseIdentifier: String {
return String(describing: self)
}
@NeilsUltimateLab
NeilsUltimateLab / ImagePickerDisplaying.swift
Created February 3, 2019 08:04
Image Picker Displaying Protocol and UIViewController extension for Image Picker.
import UIKit
import AVFoundation
import Photos
protocol ImagePickerDiplaying: class {
func pickerAction(sourceType : UIImagePickerControllerSourceType)
func alertForPermissionChange(forFeature feature: String, library: String, action: String)
func cameraAccessPermissionCheck(completion: @escaping (Bool) -> Void)
func photosAccessPermissionCheck(completion: @escaping (Bool)->Void)
}
@NeilsUltimateLab
NeilsUltimateLab / CoreDataController.swift
Last active March 12, 2019 10:00
Add Core data support to existing projects.
import Foundation
import CoreData
class CoreDataController: NSObject {
private override init() {
super.init()
}
static let shared: CoreDataController = CoreDataController()
@NeilsUltimateLab
NeilsUltimateLab / AppleMapURLGenerator.swift
Last active February 3, 2019 08:15
Generate URL with type-safe way for /Google maps.
import Foundation
import CoreLocation
extension Int {
func queryItem(for name: String) -> URLQueryItem {
return URLQueryItem(name: name, value: "\(self)")
}
}
extension String {
@NeilsUltimateLab
NeilsUltimateLab / MessageComposer.swift
Created February 3, 2019 08:18
Compose message and present MFMessageComposeViewController
import Foundation
import MessageUI
class MessageComposer: NSObject, MFMessageComposeViewControllerDelegate {
var reciepient: String?
var message: String?
weak var alertPresenter: UIViewController?
convenience init(reciepient: String?, message: String?, alertPresenter: UIViewController? = nil) {
@NeilsUltimateLab
NeilsUltimateLab / DataSourceManager.swift
Created February 3, 2019 08:21
Data Source Manager with pagination.
import Foundation
struct DataSourceManager<A> {
private var _currentPage: UInt = 1
private var _initialPageIndex: UInt = 1
init(intialPageIndex: UInt = 1, dataPerPage: Int = 10) {
self._currentPage = intialPageIndex
self._initialPageIndex = intialPageIndex
self.dataPerPage = dataPerPage