Skip to content

Instantly share code, notes, and snippets.

View DejanEnspyra's full-sized avatar

Dejan Atanasov DejanEnspyra

View GitHub Profile
@DejanEnspyra
DejanEnspyra / Obfuscator.swift
Created May 31, 2017 17:51
Obfuscation of hard-coded security-sensitive strings.
//
// Obfuscator.swift
//
// Created by Dejan Atanasov on 2017-05-31.
//
import Foundation
class Obfuscator: AnyObject {
@DejanEnspyra
DejanEnspyra / CameraHandler.swift
Last active September 12, 2023 11:00
Access iOS Camera and Photo Library with Swift 3. http://theappspace.com/swift-access-ios-camera-photo-library/
//
// CameraHandler.swift
// theappspace.com
//
// Created by Dejan Atanasov on 26/06/2017.
// Copyright © 2017 Dejan Atanasov. All rights reserved.
//
import Foundation
import UIKit
@DejanEnspyra
DejanEnspyra / polyline.swift
Created October 3, 2017 19:04
Polyline Google Maps iOS SDK
func drawRectange(){
/* create the path */
let path = GMSMutablePath()
path.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.0))
path.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.0))
path.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.2))
path.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.2))
path.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.0))
/* show what you have drawn */
@DejanEnspyra
DejanEnspyra / multipart.swift
Created July 2, 2017 07:55
Alamofire 4 — Multipart file upload with Swift 3 (http://theappspace.com/multipart-file-upload/)
func requestWith(endUrl: String, imageData: Data?, parameters: [String : Any], onCompletion: ((JSON?) -> Void)? = nil, onError: ((Error?) -> Void)? = nil){
let url = "http://google.com" /* your API url */
let headers: HTTPHeaders = [
/* "Authorization": "your_access_token", in case you need authorization header */
"Content-type": "multipart/form-data"
]
Alamofire.upload(multipartFormData: { (multipartFormData) in
@DejanEnspyra
DejanEnspyra / IAPHandler.swift
Created July 18, 2017 18:13
[SWIFT] How to add In-App Purchases in your iOS app.
//
// IAPHandler.swift
//
// Created by Dejan Atanasov on 13/07/2017.
// Copyright © 2017 Dejan Atanasov. All rights reserved.
//
import UIKit
import StoreKit
@DejanEnspyra
DejanEnspyra / polygon.swift
Created October 3, 2017 19:26
Polygon Google Maps iOS SDK
func polygon(){
// Create a rectangular path
let rect = GMSMutablePath()
rect.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.0))
rect.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.0))
rect.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.2))
rect.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.2))
// Create the polygon, and assign it to the map.
let polygon = GMSPolygon(path: rect)
@DejanEnspyra
DejanEnspyra / infowindow.swift
Last active September 7, 2020 22:26
Set up custom Info Window in Google Maps iOS SDK
extension ViewController: GMSMapViewDelegate{
/* handles Info Window tap */
func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {
print("didTapInfoWindowOf")
}
/* handles Info Window long press */
func mapView(_ mapView: GMSMapView, didLongPressInfoWindowOf marker: GMSMarker) {
print("didLongPressInfoWindowOf")
}
import Foundation
import UIKit
extension UITextField{
@IBInspectable var doneAccessory: Bool{
get{
return self.doneAccessory
}
set (hasDone) {
@DejanEnspyra
DejanEnspyra / restoreVC.swift
Created February 27, 2018 19:36
Restore Identifier UIViewController (Spotlight)
override func restoreUserActivityState(_ activity: NSUserActivity) {
if activity.activityType == CSSearchableItemActionType, let info = activity.userInfo, let selectedIdentifier = info[CSSearchableItemActivityIdentifier] as? String {
print("Selected Identifier: \(selectedIdentifier)")
}
}
@DejanEnspyra
DejanEnspyra / restore.swift
Created February 27, 2018 19:24
Restore Activity
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
let vc = (window?.rootViewController as! UINavigationController).viewControllers[0]
vc.restoreUserActivityState(userActivity)
return true
}