Skip to content

Instantly share code, notes, and snippets.

View barbaramartina's full-sized avatar
💭
About to finish my masters :) yeah!

Bar barbaramartina

💭
About to finish my masters :) yeah!
View GitHub Profile
@barbaramartina
barbaramartina / BeaconsManager.swift
Created December 18, 2025 15:55
How to implement a lightweight indoors map solution
/// In the last days, I have been playing around with a technology which is not new, but I've never looked into before. iBeacons. It's very interesting how beacons could be used to implement all sorts of applications, such as an indoor positioning system, but also an outdoor game for example, or in a very large restaurant, it could be used to identify where the customer is seating and deliver food to their table.
/// It basically consists in utilizing beacons capable units and positioning them spread across an area, registering each unit and monitoring when the users's iPhone enters the area.
/// iBeacons structure
/// The main framework involved in dealing with iBeacons is CoreLocation, I've work extensively with CoreLocation in GPS positioning logics before, but I've not yet utilized CoreLocation to track iBeacons. There is a class name CLBeacon and a set of relatively new APIs which I used for this example: CLMonitor and CLBeaconIdentifyCondition (both available since iOS 17)
/// CLBeacon
/// CLBeacon
@barbaramartina
barbaramartina / CustomSwipeActionsSwiftUI.swift
Last active September 28, 2025 10:17
Custom Swipe Actions in Lists. An alternative solution.
//
// CustomSwipeActionsSwiftUI
//
// Custom Swipe Actions in Lists are provided by default, however even if you add a title and an icon to the SwipeAction,
// SwiftUI will decide internally which one to you (or both). So you do not have full control on how your swipe action
// button appears... I was implementing a custom swipe action and discovered many pitfalls in the List + SwipeActions
// combination in SwiftUI. Checkout how I solved it with a dragGesture and views on a ScrollView.
// It's a lot of craft to make these custom actions work, so I do not recommend to use such a fancy alternative unless
// you have extremely good reasons since you will loose the capabilities offered by the system to do swipe, drags,
// gestures interactions calculations on its own, and it will cost you on maintenance in the future.
@barbaramartina
barbaramartina / SFSymbol.swift
Created August 1, 2025 20:39
SFSymbols in an enum
import Foundation
/// the biggest enum ever in my life :)
/// All SFSymbols names in one enum
enum SFSymbol: String, CaseIterable {
case squareandarrowup = "square.and.arrow.up"
case squareandarrowupfill = "square.and.arrow.up.fill"
case squareandarrowupcircle = "square.and.arrow.up.circle"
case squareandarrowupcirclefill = "square.and.arrow.up.circle.fill"
case squareandarrowupbadgeclock = "square.and.arrow.up.badge.clock"
// example to show how to check if core data can infers a mapping model by itself
// do not forget to add the .momd to you model object package!!!!
// https://developer.apple.com/documentation/coredata/nsmappingmodel/1506468-inferredmappingmodelforsourcemod
// SWIFT 4
if let previousModelURL = Bundle.main.url(forResource: "YOURMODELNAME.momd/YOURMODELVERSION 2", withExtension: "mom"),
let previousModel = NSManagedObjectModel(contentsOf: previousModelURL),
let currentModelURL = Bundle.main.url(forResource: "YOURMODELNAME.momd/YOURMODELVERSION 3", withExtension: "mom"),
let currentModel = NSManagedObjectModel(contentsOf: currentModelURL) {
//
// CoreDataStackTheOldWay.swift
// CoreDataShowcase
//
// Created by Barbara Rodeker on 24.09.17.
//
// THIS CLASS CONTAINS PROPERTIES THAT NEEDED TO BE
// CREATED FOR CORE DATA BEFORE THE EXISTENCE OF NSPERSISTENTCONTAINER (added in iOS10)
//
// SWIFT 4
//
// CoreDataStack.swift
// CoreDataShowcase
//
// Created by Barbara Rodeker on 31.10.17.
//
// THIS CLASS CONTAINS ALL THE REQUIRED PROPERTIES THAT NEED TO BE CREATED
// FOR CORE DATA AFTER NSPersistentContainer was added in IOS 10
//
// SWIFT 4
// Create a persistent container with an specific description for the stores
private(set) lazy var container: NSPersistentContainer = {
let description = NSPersistentStoreDescription()
description.type = NSSQLiteStoreType
description.shouldInferMappingModelAutomatically = false
description.shouldMigrateStoreAutomatically = true
let container = NSPersistentContainer(name: CoreDataStackTheNewWay.modelName)
container.persistentStoreDescriptions = [description]
import Foundation
// Extension on PropertyListSerialization to read an array from a property list file
extension PropertyListSerialization {
// Takes the name of the PLIST file to be read. Name must be provided without extension.
// returns an optional array if the file can be opened and parsed properly.
// - Parameters:
// - named String with the filename. No extension .plist needed
static func arrayFromPlist(named name: String) -> [Any]? {
// Model used -> https://free3d.com/download-page.php?url=rose-31675
let scene = SCNScene(named: "rose.obj")
// Set up the SceneView
sceneView.autoenablesDefaultLighting = true
sceneView.allowsCameraControl = true
sceneView.scene = scene
sceneView.backgroundColor = .black
@barbaramartina
barbaramartina / BlurEffect-Swift3.swift
Created July 9, 2017 12:19
Apply blur effect to a view in Swift 3
let effectView = UIVisualEffectView()
effectView.frame = view.bounds
effectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(effectView)
let e = UIBlurEffect(style: .dark)
effectView.effect = e