Skip to content

Instantly share code, notes, and snippets.

View mingsai's full-sized avatar
🎯
Focusing

Tommie N. Carter, Jr. mingsai

🎯
Focusing
View GitHub Profile
@mnbayan
mnbayan / MKMapViewExtension.swift
Created February 23, 2015 02:33
MKMapView extension to center map to coordinates with defined zoom level using Swift language
//
// MKMapViewExtension.swift
// AutocompleteTextfieldSwift
//
// Created by Mylene Bayan on 2/22/15.
// Copyright (c) 2015 MaiLin. All rights reserved.
//
import Foundation
import MapKit
@ColinEberhardt
ColinEberhardt / Swift Events
Created February 11, 2015 09:15
An eventing mechanism for Swift
/// An object that has some tear-down logic
public protocol Disposable {
func dispose()
}
/// An event provides a mechanism for raising notifications, together with some
/// associated data. Multiple function handlers can be added, with each being invoked,
/// with the event data, when the event is raised.
public class Event<T> {
@cfr
cfr / CocoaLumberjack.swift
Last active May 9, 2018 06:46 — forked from stigi/CocoaLumberjack.swift
Swift 1.2 CocoaLumberjack wrapper
// Updated to Swift 1.2 and CocoaLumberjack 2.0.0-rc by Stan Serebryakov on 2015-02-16
import Foundation
extension DDLog {
private struct State {
static var logLevel: DDLogLevel = .Error
static var logAsync: Bool = true
}
let array = ["P","Q","R","S","T","P","R","A","T","B","C","P","P","P","P","P","C","P","P","J"]
extension Array {
func unique<T: Equatable>() -> [T] {
return self.reduce([T](), combine: { (array, value) -> [T] in
var result = array
let valAsT = value as T
if (!contains(array, valAsT)) {
result.append(valAsT)
}
@niklasberglund
niklasberglund / add_lib_with_xcodeproj.rb
Created September 13, 2014 08:17 — forked from onevcat/add_lib_with_xcodeproj.rb
Example of how to use the ruby gem xcodeproj to add a library to the Frameworks group of a project. Forked and updated to work with updated version of xcodeproj.
require 'xcodeproj'
project_path = "your_project_path";
# Create project object
project = Xcodeproj::Project.new(project_path);
lib_path = "your_lib_path";
# Add the lib file as a reference
libRef = project['Frameworks'].new_file(lib_path);
@kristopherjohnson
kristopherjohnson / reconfigureVisibleCells.m
Last active January 16, 2020 18:59
Update visible cells from a UITableViewController without calling -[UITableView reloadData]
- (void)reconfigureVisibleCells
{
NSInteger sectionCount = [self numberOfSectionsInTableView:self.tableView];
for (NSInteger section = 0; section < sectionCount; ++section) {
NSInteger rowCount = [self tableView:self.tableView numberOfRowsInSection:section];
for (NSInteger row = 0; row < rowCount; ++row) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
@kristopherjohnson
kristopherjohnson / dispatch_once.swift
Created August 12, 2014 16:25
Example of using dispatch_once() in Swift
import Foundation
var token: dispatch_once_t = 0
func test() {
dispatch_once(&token) {
println("This is printed only on the first call to test()")
}
println("This is printed for each call to test()")
}
@venkatperi
venkatperi / KVOTest
Created August 11, 2014 18:38
KVOTests
//
// KVOTests.swift
// SwiftStuff
//
// Created by Venkat Peri on 8/11/14.
// Copyright (c) 2014 vperi. All rights reserved.
//
import Cocoa
import XCTest
@soffes
soffes / CLLocationCoordinate2D+Equatable.swift
Last active September 11, 2024 14:15
Add Equatable to CLLocationCoordinate2D
import CoreLocation
extension CLLocationCoordinate2D: Equatable {}
public func ==(lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool {
return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude
}
@szehnder
szehnder / DataProvider.swift
Last active December 23, 2019 12:13
Pattern for async callback between a view controller and a dataprovider singleton
typealias ServiceResponse = (NSDictionary?, NSError?) -> Void
class DataProvider: NSObject {
var client:AFHTTPRequestOperationManager?
let LOGIN_URL = "/api/v1/login"
class var sharedInstance:DataProvider {
struct Singleton {
static let instance = DataProvider()