Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Barbara Martina Rodeker barbaramartina

🎯
Focusing
View GitHub Profile
View CoreDataCheckIfInferredAutomaticMappingIsPossible.swift
// 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) {
View CoreDataStackTheOldWayPreiOS10.swift
//
// 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
View SimpleCoreDataStackSinceiOS10.swift
//
// 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
View CoreDataPersistentContainer.swift
// 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]
View ReadPlistInSwift.swift
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]? {
View loadOBJModelIntoScene.swift
// 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 Jul 9, 2017
Apply blur effect to a view in Swift 3
View BlurEffect-Swift3.swift
let effectView = UIVisualEffectView()
effectView.frame = view.bounds
effectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(effectView)
let e = UIBlurEffect(style: .dark)
effectView.effect = e
View blurEffectFadeIniOS10.swift
// iOS 10 working way to fade in a blurred view (changing alpha in the container does not work on iOS 10)
let effectView = UIVisualEffectView()
effectView.frame = toast.bounds
effectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(effectView) //replace view with whatever view you want to blur
UIView.animate(withDuration: 0.2) {
let blur = UIBlurEffect(style: .light)
effectView.effect = blur
@barbaramartina
barbaramartina / Swift 3: Advanced Notifications: Example of a Content Extension.swift
Created Nov 5, 2016
Swift 3: how to implement a content extension that read an image attachment and intercept actions.
View Swift 3: Advanced Notifications: Example of a Content Extension.swift
//
// NotificationViewController.swift
// Content
//
// Created by Barbara Rodeker on 28/09/16.
// Copyright © 2016 Barbara Rodeker. All rights reserved.
//
import UIKit
import UserNotifications
@barbaramartina
barbaramartina / Swift 3: How to implement a service extension.swift
Created Nov 5, 2016
Swift 3: implement a service extension and download an image attachment.
View Swift 3: How to implement a service extension.swift
//
// NotificationService.swift
// Service
//
// Created by Barbara Rodeker on 28/09/16.
// Copyright © 2016 Barbara Rodeker. All rights reserved.
//
import UserNotifications