Skip to content

Instantly share code, notes, and snippets.

Adrian AdrianBinDC

  • Washington, DC
Block or report user

Report or block AdrianBinDC

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View new-in-4-2.md

New in Swift 4.2

Summary from HackingWithSwift.com

CaseIterable

The CaseIterable protocol provides an allCases method that turns all of your cases into an array.

enum Pasta: String, CaseIterable {
    case canneloni = "Cannelloni pasta"
@AdrianBinDC
AdrianBinDC / country-bounding-boxes.md
Last active Jul 12, 2018
Bounding Boxes by Country
View country-bounding-boxes.md

Country Bounding Boxes

The following is a list of countres by ISO code, the country name, and the country's bounding box with some extra data in CSV format.

Adapted from ISO-3166-Countries-with-Regional-Codes

Bounding boxes from Bounding Box Tool.

name,alpha-2,alpha-3,country-code,iso_3166-2,region,sub-region,intermediate-region,region-code,sub-region-code,intermediate-region-code,minLong,minLat,maxLong,maxLat
Afghanistan,AF,AFG,4,ISO 3166-2:AF,Asia,Southern Asia,,142,34,,60.5284298033,29.318572496,75.1580277851,38.4862816432
@AdrianBinDC
AdrianBinDC / ConvertDistances.swift
Created Jul 11, 2018
Convert distances from one unit of measurement to another
View ConvertDistances.swift
extension Double {
func convert(from originalUnit: UnitLength, to convertedUnit: UnitLength) -> Double {
return Measurement(value: self, unit: originalUnit).converted(to: convertedUnit).value
}
}
/*
let miles = 26.2
let meters = miles.convert(from: .miles, to: .meters)
*/
@AdrianBinDC
AdrianBinDC / ConnectivityUtil.swift
Last active Jul 28, 2018
Connectivity Utility Implementation using Reachability
View ConnectivityUtil.swift
//
// ConnectivityUtility.swift
//
// Created by Adrian Bolinger on 7/10/18.
// Copyright © 2018 Adrian Bolinger. All rights reserved.
//
import UIKit
import Reachability
@AdrianBinDC
AdrianBinDC / MapRegionUtility.swift
Last active Oct 23, 2019
Generate a MKCoordinateRegions for continents and major oceans
View MapRegionUtility.swift
//
// MapRegionUtility.swift
// QuakeData
//
// Created by Adrian Bolinger on 7/9/18.
// Copyright © 2018 Adrian Bolinger.
//
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@AdrianBinDC
AdrianBinDC / gist:a8da4748181d86203689bc369fa01ed2
Last active Jul 5, 2018
Set MKMapRegion to display a specific zoom scale
View gist:a8da4748181d86203689bc369fa01ed2

Set Zoom Scale on Map Region in Swift

MKCoordinateRegionMakeWithDistance can be used to make a region with a specified distance (in meters).

Here is the method signature:

func MKCoordinateRegionMakeWithDistance(_ centerCoordinate: CLLocationCoordinate2D, 
                                        _ latitudinalMeters: CLLocationDistance, 
                                        _ longitudinalMeters: CLLocationDistance) -> MKCoordinateRegion

Use an extension to get your desired distance and convert it into meters.

@AdrianBinDC
AdrianBinDC / ConvertDistances.md
Last active Jul 5, 2018
Convert Distances in Swift using Measurement
View ConvertDistances.md

Distance conversion in Swift

As of iOS 10, the Measurement class was introduced, which obviates the need lookup values and create constants to convert values. Here is a simple extension to convert distances.

extension Double {
  func convert(from originalUnit: UnitLength, to convertedUnit: UnitLength) -> Double {
    return Measurement(value: self, unit: originalUnit).converted(to: convertedUnit).value
  }
}
View Unofficial-APOD.md

Unofficial APOD

Unofficial APOD utilizes Alamofire to request data from NASA's APOD servers. The response data is returned in JSON format. Unofficial APOD utilizes structs conforming to Swift's Codable protocol to parse the JSON returns and persists the data in Core Data. Prior to requesting information from NASA's servers, Unofficial APOD first checks to see if it has already retrieved the data before making a network request.

NASA returns a JSON with text data about the image, but no binary data is returned. Unofficial APOD utilizes AlamofireImage to download the most recent 60 days' worth of non-copywritten images on a background thread and persists them locally to speed up performance for the user.

Copywritten images are not stored on the device. So the user doesn't see an empty screen, the UICircularProgressRing framework is configured to display the status of the image download.

Giv

You can’t perform that action at this time.