Coder Social home page Coder Social logo

nagyist / graph Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cosmicmind/graph

0.0 2.0 0.0 32.95 MB

A semantic database for iOS in Swift.

Home Page: http://graphswift.io

License: BSD 3-Clause "New" or "Revised" License

Ruby 0.18% Swift 99.24% Objective-C 0.58%

graph's Introduction

Graph

Welcome to Graph

Graph is a data-driven framework for CoreData. It comes complete with iCloud support and the ability to create as many local and cloud instances as you would like.

Features

  • iCloud Support
  • Multi Storage Support
  • Thread Safe
  • Store Any Data Type, Including Binary Data
  • Relationship Modeling
  • Action Modeling For Analytics
  • Model With Graph Theory and Set Theory
  • Faceted Search API
  • Asynchronous / Synchronous Saving
  • Data-Driven Architecture
  • Data Model Observation
  • Comprehensive Unit Test Coverage
  • Example Projects

Requirements

  • iOS 8.0+ / Mac OS X 10.9+
  • Xcode 7.3+

Communication

  • If you need help, use Stack Overflow. (Tag 'cosmicmind')
  • If you'd like to ask a general question, use Stack Overflow.
  • If you found a bug, and can provide steps to reliably reproduce it, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Installation

Embedded frameworks require a minimum deployment target of iOS 8 or OS X Mavericks (10.9).

Visit the Installation page to learn how to install Graph using CocoaPods and Carthage.

Changelog

Graph is a growing project and will encounter changes throughout its development. It is recommended that the Changelog be reviewed prior to updating versions.

Examples

  • Visit the Examples directory to see example projects using Graph.

A Tour

Entity

An Entity is a model object that represents a person, place, or thing. It may store property values and be a member of groups.

For example, creating a Person Entity:

let graph = Graph()

let person = Entity(type: "Person")
person["firstName"] = "Elon"
person["lastName"] = "Musk"
person["age"] = 41

person.addToGroup("Male")
person.addToGroup("Inspiring")

graph.async()

Learn More About Entities

Relationship

A Relationship is a model object that forms a connection between two Entities. It may store property values and be a member of groups.

let graph = Graph()

let person = Entity(type: "Person")
person["firstName"] = "Mark"
person["lastName"] = "Zuckerberg"

let company = Entity(type: "Company")
company["name"] = "Facebook"

let employee = Relationship(type: "Employee")
employee["startDate"] = "February 4, 2004"
employee.addToGroup("CEO")
employee.addToGroup("Founder")

employee.subject = person
employee.object = company

graph.async()

Learn More About Relationships

Action

An Action is a model object that forms a connection between many Entities. It may store property values and be a member of groups.

let graph = Graph()

let user = Entity(type: "User")
user["name"] = "Daniel"

let book1 = Entity(type: "Book")
book1["title"] = "Learning Swift"
book1.addToGroup("Programming")

let book2 = Entity(type: "Book")
book2["title"] = "The Holographic Universe"
book2.addToGroup("Physics")

let purchased = Action(type: "Purchased")
purchased.addToGroup("Pending")

purchased.addSubject(user)
purchased.addObject(book1)
purchased.addObject(book2)

graph.async()

Learn More About Actions

Data Driven

As data moves through your application, the state of information may be observed to create a reactive experience. Below is an example of watching when a "User Clicked a Button".

// Set Protocol to GraphDelegate.

let graph = Graph()
graph.delegate = self

graph.watchForAction(types: ["Clicked"])

let user: Entity = Entity(type: "User")
let clicked = Action(type: "Clicked")
let button = Entity(type: "Button")

clicked.addSubject(user)
clicked.addObject(button)

graph.async()

// Delegate method.
func graphDidInsertAction(graph: Graph, action: Action, fromCloud: Bool) {
    switch(action.type) {
    case "Clicked":
      print(action.subjects.first?.type) // User
      print(action.objects.first?.type) // Button
    case "Swiped":
      // Handle swipe.
    default:break
    }
 }

Faceted Search

To explore the intricate relationships within Graph, the search API adopts a faceted design. The below examples show how to use the Graph search API:

Searching multiple Entity types.

let graph = Graph()
let collection = graph.searchForEntity(types: ["Photo", "Video"])

Searching multiple Entity groups.

let graph = Graph()
let collection = graph.searchForEntity(groups: ["Media", "Favorites"])

Searching multiple Entity properties.

let graph = Graph()
let collection = graph.searchForEntity(properties: [(key: "name", value: "Eve"), ("age", 27)])

Searching multiple facets simultaneously will aggregate all results into a single collection.

let graph = Graph()
let collection = graph.searchForEntity(types: ["Photo", "Friends"], groups: ["Media", "Favorites"])

Filters may be used to narrow in on a search result. For example, searching a book title and group within purchases.

let graph = Graph()

let collection = graph.searchForAction(types: ["Purchased"]).filter { (action: Action) -> Bool in
	if let entity = action.objects.first {
		if "Book" == entity.type && "The Holographic Universe" == entity["title"] as? String  {
			return entity.memberOfGroup("Physics")
		}
	}
	return false
}

License

Copyright (C) 2015 - 2016, CosmicMind, Inc. http://cosmicmind.io. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this
    list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of CosmicMind nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

graph's People

Contributors

danieldahan avatar adam88labs avatar michaelreyder avatar mohpor avatar ninjaishere avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.