This file contains 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
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations | |
{ | |
CLLocation *newLocation = locations.lastObject; | |
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow]; | |
if (locationAge > 5.0) return; | |
if (newLocation.horizontalAccuracy < 0) return; | |
// Needed to filter cached and too old locations |
This file contains 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
@interface | |
+(id)sharedInstance; | |
@implementation | |
- (id)init { | |
self = [super init]; | |
#if !(TARGET_IPHONE_SIMULATOR) |
This file contains 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
[string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; |
This file contains 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
f you are on OS X 10.8 or iOS 6 you can use the new NSUUID class to generate a string UUID, without having to go to Core Foundation: | |
NSString *uuidString = [[NSUUID UUID] UUIDString]; | |
// Generates: 7E60066C-C7F3-438A-95B1-DDE8634E1072 | |
But mostly, if you just want to generate a unique string for a file or directory name then you can use NSProcessInfo's globallyUniqueString method like: | |
NSString *uuidString = [[NSProcessInfo processInfo] globallyUniqueString]; | |
// generates 56341C6E-35A7-4C97-9C5E-7AC79673EAB2-539-000001F95B327819 | |
It's not a formal UUID, but it is unique for your network and your process and is a good choice for a lot of cases. |
This file contains 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
//MARK: Address Book methods | |
func createAddressBook() -> Bool { | |
if self.adbk != nil { | |
return true | |
} | |
var err : Unmanaged<CFError>? = nil | |
let adbk : ABAddressBook? = ABAddressBookCreateWithOptions(nil, &err).takeRetainedValue() | |
if adbk == nil { | |
print(err) |
This file contains 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 spotLighIndexingForContact(contact: MainContact) -> AnyObject | |
{ | |
if #available(iOS 9, *) { | |
let attributeSet : CSSearchableItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeImage as String) | |
let name : String = contact.firstname + " " + contact.lastname | |
attributeSet.title = name | |
attributeSet.contentDescription = "Main Contact" | |
This file contains 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 showMessage(message : String, delay : NSTimeInterval, color : UIColor, completion: boolClosure?) | |
{ | |
dispatch_async(self.GlobalMainQueue) | |
{ | |
guard let window = appDelegate.window else | |
{ | |
completion!(result: false,error: nil) | |
return | |
} | |
This file contains 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
// | |
// ContactsManager.swift | |
// main | |
// | |
// Created by Nero Wolfe on 14/07/16. | |
// Copyright © 2016 Incoding. All rights reserved. | |
// | |
import UIKit | |
import Contacts |
This file contains 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
let backgroundQ = DispatchQueue.global(attributes: .qosDefault) | |
let group = DispatchGroup() | |
var someData:[Data] = [] | |
for number in 0..<n { | |
group.enter() | |
backgroundQ.async(group: group, execute: { | |
if number > 50 { | |
fill.append(number) | |
} |
This file contains 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 Foundation | |
extension UIView{ | |
func border(color : UIColor, side : String, width : CGFloat) | |
{ | |
var borderFrame = CGRect.zero | |
switch side { | |
case "left": | |
borderFrame = CGRect(x: 0.0, y: 0.0, width: width, height: self.frame.size.height) |
OlderNewer