{"id":17090830,"url":"https://github.com/phimage/philipsstack","last_synced_at":"2025-04-12T22:28:48.784Z","repository":{"id":32365699,"uuid":"35941784","full_name":"phimage/PhiLipsStack","owner":"phimage","description":"(do not use) PhiLipsStack aims to create a CoreData stack from model to context and provide some functions on your managed object which use by default the default stack context but not only","archived":false,"fork":false,"pushed_at":"2017-02-05T15:22:46.000Z","size":805,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T11:37:45.737Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phimage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-20T10:36:36.000Z","updated_at":"2023-03-06T19:21:08.000Z","dependencies_parsed_at":"2022-08-21T04:50:44.165Z","dependency_job_id":null,"html_url":"https://github.com/phimage/PhiLipsStack","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FPhiLipsStack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FPhiLipsStack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FPhiLipsStack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FPhiLipsStack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phimage","download_url":"https://codeload.github.com/phimage/PhiLipsStack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248639295,"owners_count":21137820,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T13:56:51.386Z","updated_at":"2025-04-12T22:28:48.766Z","avatar_url":"https://github.com/phimage.png","language":"Swift","readme":"(deprecated, please do not use)\n\n# PhiLipsStack - ϕ:lips: - embrace [CoreData](https://developer.apple.com/library/ios/documentation/DataManagement/Devpedia-CoreData/coreDataOverview.html#//apple_ref/doc/uid/TP40010398-CH28-SW1)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat\n            )](http://mit-license.org) [![Platform](http://img.shields.io/badge/platform-iOS/MacOS-lightgrey.svg?style=flat\n             )](https://developer.apple.com/resources/) [![Language](http://img.shields.io/badge/language-swift-orange.svg?style=flat\n             )](https://developer.apple.com/swift) [![Issues](https://img.shields.io/github/issues/phimage/PhiLipsStack.svg?style=flat\n           )](https://github.com/phimage/Prephirences/issues) [![Cocoapod](http://img.shields.io/cocoapods/v/PhiLipsStack.svg?style=flat)](http://cocoadocs.org/docsets/PhiLipsStack/)\n\n[\u003cimg align=\"left\" src=\"logo-128x128.png\" hspace=\"20\"\u003e](#logo) PhiLipsStack aims to create a [CoreData stack](https://developer.apple.com/library/ios/documentation/DataManagement/Devpedia-CoreData/coreDataStack.html#//apple_ref/doc/uid/TP40010398-CH25-SW1) from [model](https://developer.apple.com/library/ios/documentation/DataManagement/Devpedia-CoreData/managedObjectContext.html) to [context](https://developer.apple.com/library/ios/documentation/DataManagement/Devpedia-CoreData/managedObjectContext.html) and provide some functions on your [managed object](https://developer.apple.com/library/ios/documentation/DataManagement/Devpedia-CoreData/managedObject.html) which use by default the default stack context but not only\n\n```swift\nlet context = NSManagedObjectContext.defaultContext\nvar object: MyManagedObject = MyManagedObject.create()\nobject.delete()\n```\nWith PhiLipsStack you should use [QueryKit](https://github.com/QueryKit/QueryKit) to create query and the command line tool [mogenerator](https://github.com/rentzsch/mogenerator) to generate your `NSManagedObject` from model\n\n## Contents ##\n- [Stack and optional configuration](#stack-and-optional-configuration)\n- [Play with managed objects: CRUD](#play-with-managed-objects-crud)\n- [Setup](#setup)\n- [Licence](#licence)\n- [Logo](#logo)\n\n## Stack and optional configuration ##\nA `CoreDataStack` is composed of three elements\n- [`managedObjectModel`](#the-model)\n- [`persistentStoreCoordinator`](#the-persistance-store-coordinator)\n- [`managedObjectContext`](#the-managed-object-context)\n\nand initialized with persistance store type and optionnal URL\n\n```swift\nvar myStack = CoreDataStack(storeType: .SQLite, storeURL: anURL)\n```\nA default one is accessible with SQLite type and your application directory\n```swift\nCoreDataStack.defaultStack\n```\n\n### [The model](https://developer.apple.com/library/ios/documentation/DataManagement/Devpedia-CoreData/managedObjectModel.html) ###\n\nThe stack use your application name as model name (ex: model file `MyAppName.xcdatamodel`)\nIf your model have another name, you can set your own model name by calling `myStack.modelName = \"MyModelName\"`\n```swift\nCoreDataStack.defaultStack.modelName = \"MyModelName\"\n```\n:warning: This must be done before requesting any of `managedObjectContext`, `persistentStoreCoordinator`, `managedObjectModel` or calling framework functions\n\n### [The persistance store coordinator](https://developer.apple.com/library/ios/documentation/DataManagement/Devpedia-CoreData/persistentStoreCoordinator.html) ###\n\nBy default the persistance store coordinatore is initialized with [automigrate option](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSPersistentStoreCoordinator_Class/index.html#//apple_ref/doc/constant_group/Migration_Options)\n*To change this behaviour set stack `autoMigrate` to false*\n\nIf not able to load data from current persistance files, all data are removed (`removeStore()`) and new empty files are created.\n*To change this behaviour set `removeIncompatibleStore` to false*\n\n### [The managed object context](https://developer.apple.com/library/ios/documentation/DataManagement/Devpedia-CoreData/managedObjectContext.html) ###\n\nThe default context can be accessed by class variable on `NSManagedObjectContext`\n```swift\nNSManagedObjectContext.defaultContext\n```\n*This default context is the `managedObjectContext` attribute of default stack `CoreDataStack.defaultStack`. So you can change the defaultStack by your own if necessary*\n\n## Play with managed objects: CRUD ##\n\n### Create\nYour  `NSManagedObject` must contains `@objc(classname)` or you must override `entityName` class var\n\n```swift\n@objc(MyEntity)\nclass MyEntity: NSManagedObject {\n\t@NSManaged var title: String\n\t@NSManaged var valid: NSNumber\n}\n```\n*You could use the command line tool [mogenerator](https://github.com/rentzsch/mogenerator) to generate your `NSManagedObject` from model*\n\nThen to create an object in default context\n```swift\nvar entity = MyEntity.create()\nvar entity = MyEntity.createWithAttribute([key:value])\n```\nTo create only if not exists, two useful functions\n```swift\nvar entity: MyEntity = MyEntity.findFirstOrCreate()\nvar anotherEntity: MyEntity.findFirstOrCreateWithPredicate(aPredicate)\n```\n\n### Read/Fetch\nGet all object of one type\n```swift\nif let entities = MyEntity.all() ? [Entity] { .. }\nlet entityCount = MyEntity.count()\n```\nSome basic filtering using `NSPredicate`\n```\nif let entities = MyEntity.find(predicate) ? [Entity] { .. }\nlet entityCount = MyEntity.count(predicate)\n```\nFor more advanced fetch with predicates, you should use [QueryKit](https://github.com/QueryKit/QueryKit).\n```swift\nlet myEntityQuerySet = QuerySet\u003cMyEntity\u003e(NSManagedObjectContext.defaultContext, MyEntity.entityName)\n```\n\nThere is a mogerator templates for swift [here: machine.swift.motemplate](https://github.com/phimage/mogenerator-template)\n\n### Update and Save\nUpdate your objects as usual by modifying attributes and relations, then you can save immediately your object\n```swift\nentity.save()\n```\nBut it is recommanded to save the context when application will terminate or did enter background - see [application delegate example](/Sample/AppDelegate.swift)\n```swift\nstack.save()\n```\n### Delete\nDelete object is as simple as following\n```swift\nentity.delete()\n```\nYou can also delete all objects of specific type\n```swift\nEntity.deleteAll()\n```\n### Error handling\nMost of the functions provided by this framework allow to pass an error handler, a block of type `(NSError) -\u003e Void`\n\n```swift\nentity.delete { (error) -\u003e () in\n\n}\nEntity.find(NSPredicate(value: true)) { (error) -\u003e () in\n\n}\n```\nIf no error handler is provided, you can access the last error handled by the stack\n```swift\nif let error = myStack.lastError {..}\n```\n\nAt application start you can also check stack validity (context not nil)\n```swift\nif !myStack.valid() {\n   // log and application shutdown\n}\n// or with error handler\nmyStack.valid((error: NSError)  in {\n    // log and application shutdown\n}\n```\n# Setup #\n\n## Using xcode project ##\n\n1. Drag PhiLipsStack.xcodeproj to your project/workspace or open it to compile it\n2. Add the PhiLipsStack framework to your project\n\n## Using [cocoapods](http://cocoapods.org/) ##\n\nAdd `pod 'PhiLipsStack'` to your `Podfile` and run `pod install`. \n\nAdd `use_frameworks!` to the end of the `Podfile`.\n\n# Licence #\n```\nThe MIT License (MIT)\n\nCopyright (c) 2015 Eric Marchand (phimage)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n\n# Misc #\n![haroopad icon](http://pad.haroopress.com/assets/images/logo-small.png) Readme done with [Haroopad](https://github.com/rhiokim/haroopad)\n## Logo ##\nInspired by [apple swift logo](http://en.wikipedia.org/wiki/File:Apple_Swift_Logo.png)\n### Why a logo?\nI like to see an image for each of my project when I browse them with [SourceTree](http://www.sourcetreeapp.com/)\n## Core Data Combo\n![](CoreDataCombo.png)\n*mogenerator, PhiLipsStack, QueryKit*\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphimage%2Fphilipsstack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphimage%2Fphilipsstack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphimage%2Fphilipsstack/lists"}