Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View barbaramartina's full-sized avatar

Bar barbaramartina

View GitHub Profile
// 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
// 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 November 5, 2016 11:12
Swift 3: how to implement a content extension that read an image attachment and intercept actions.
//
// 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 November 5, 2016 11:10
Swift 3: implement a service extension and download an image attachment.
//
// NotificationService.swift
// Service
//
// Created by Barbara Rodeker on 28/09/16.
// Copyright © 2016 Barbara Rodeker. All rights reserved.
//
import UserNotifications