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 | |
import CoreLocation | |
class LocationManager: NSObject { | |
private let locationManager = CLLocationManager() | |
override init() { |
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: - Get Placemark | |
extension LocationManager { | |
func getPlace(for location: CLLocation, | |
completion: @escaping (CLPlacemark?) -> Void) { | |
let geocoder = CLGeocoder() | |
geocoder.reverseGeocodeLocation(location) { placemarks, error in | |
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
class LocationManager: NSObject { | |
// - Private | |
private let locationManager = CLLocationManager() | |
// - API | |
public var exposedLocation: CLLocation? { | |
return self.locationManager.location |
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
class ViewController: UIViewController { | |
// - Outlets | |
@IBOutlet weak var locationLabel: UILabel! | |
// - Constants | |
private let locationManager = LocationManager() | |
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: - Get Location | |
extension LocationManager { | |
func getLocation(forPlaceCalled name: String, | |
completion: @escaping(CLLocation?) -> Void) { | |
let geocoder = CLGeocoder() | |
geocoder.geocodeAddressString(name) { placemarks, error in | |
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 UIKit | |
import MapKit | |
class ViewController: UIViewController { | |
// - Outlets | |
@IBOutlet weak var locationLabel: UILabel! | |
@IBOutlet weak var mapView: MKMapView! |
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 twoSum(_ nums: [Int], _ target: Int) -> [Int] { | |
// Iterate through every element in numbers | |
for (i, number1) in numbers.enumerated() { | |
/** | |
For every iteration, | |
iterate through numbers, | |
where i does not equal j. | |
*/ | |
for (j, number2) in numbers.enumerated() where i != j { | |
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 twoSum(_ nums: [Int], _ target: Int) -> [Int] { | |
/** | |
Init an empty dictionary. | |
The value will be the array element. | |
The key will be the index of the element. | |
*/ | |
var hashMap: [Int: Int] = [:] | |
// Iterate through every element in numbers | |
for (i, element) in numbers.enumerated() { | |
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 addTwoNumbers(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? { | |
// Get a mutable reference to each head of l1 and l2 | |
var currentL1: ListNode? = l1 | |
var currentL2: ListNode? = l2 | |
// Create a reference to a node we're going to append on | |
var sumList: ListNode? = ListNode(-1) | |
// And a reference to its head |
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 deleteNode(_ node: ListNode?) { | |
// First we assign next's .value | |
node?.val = node?.next?.val ?? Int() | |
// And then next's .next | |
node?.next = node?.next?.next | |
} |
OlderNewer