{"id":20003541,"url":"https://github.com/nathanborror/nbkit","last_synced_at":"2026-05-13T04:31:39.272Z","repository":{"id":8709024,"uuid":"10376647","full_name":"nathanborror/NBKit","owner":"nathanborror","description":"Some stuff I use for prototyping.","archived":false,"fork":false,"pushed_at":"2015-10-24T18:18:07.000Z","size":512,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-01-12T13:26:15.360Z","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":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nathanborror.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":"2013-05-30T06:10:59.000Z","updated_at":"2018-11-26T15:43:04.000Z","dependencies_parsed_at":"2022-11-28T10:34:12.147Z","dependency_job_id":null,"html_url":"https://github.com/nathanborror/NBKit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanborror%2FNBKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanborror%2FNBKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanborror%2FNBKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanborror%2FNBKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nathanborror","download_url":"https://codeload.github.com/nathanborror/NBKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241442663,"owners_count":19963648,"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-11-13T05:26:08.302Z","updated_at":"2026-05-13T04:31:39.103Z","avatar_url":"https://github.com/nathanborror.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NBKit\n\nNBKit is a collection of tools to make prototyping iOS apps easier.\n\n#### Cache.swift\n\nCache is a dead simple way to cache objects temporarily to help reduce the amount of network requests. A great use-case is when you need to cache image data during a session.\n\nExample of setting and getting:\n\n``` swift\nif let lolcat = Cache.shared.get(\"lolcat.jpg\") as? UIImage {\n  // do something with cached image\n} else {\n  // load the image then cache it\n  Cache.shared.set(\"lolcat.jpg\", obj:myImage)\n}\n```\n\n#### JSON.swift\n\nJSON is a collection of enums, classes and functions for parsing JSON into pre-defined structs or classes that represent the data models you're choosing to work with. It's heavly inspired by this [NSScreencast episode](http://nsscreencast.com/episodes/130-swift-json-redux-part-1).\n\nExample of a Book struct that implements the [JSONDecode protocol](https://github.com/nathanborror/NBKit/blob/master/NBKit/NBKit/JSON.swift#L91):\n\n``` swift\nstruct Book: JSONDecode {\n  let id:Int\n  let title:String\n  let plot:String?\n  \n  static func fromJSON(j:JSValue) -\u003e Book? {\n    switch j {\n    case .JSObject(let d):\n      return Book(\n        id:     d[\"id\"] \u003e\u003e\u003e JSInt.fromJSON ?? 0,\n        title:  d[\"title\"] \u003e\u003e\u003e JSString.fromJSON ?? \"\",\n        plot:   d[\"plot\"] \u003e\u003e\u003e JSString.fromJSON\n      )\n    default:\n      return nil\n  }\n}\n```\n\nImagine you've made a request (using NSURLSession or Alamofire) for a list of books. You've probably got an NSData object so you'd do the following to convert it into an array of Book objects:\n\n``` swift\nlet json = JSValue.decode(data)\nlet books = json \u003e\u003e\u003e JSArray\u003cBook, Book\u003e.fromJSON\n```\n\n#### Layout.swift\n\nLayout is a more convenient way to programmatically work with [Auto-Layout](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html).\n\nExample using a few pre-defined views within a view controller:\n\n``` swift\n// Positions a button 44pt tall 128pt from the top of the screen \n// and fills the horizontal space with the standard 8pt of margin.\nLayout([\"submit\": submitButton]).with([\n  \"H:|-[submit]-|\",\n  \"V:|-128-[submit(44)]\"\n])\n\n// Fills the entire horizontal and vertical space of the superview\nLayout([\"photo\":myPhoto])\n  .add(\"H:|[photo]|\")\n  .add(\"V:|[photo]|\")\n\n// Alternative\nLayout.max(myPhoto)\n\n```\n\n#### Regex.swift\n\nRegex is a more convenient way to work with regular expressions.\n\n--\n\n#### Deprecated\n\n* Parser.swift is deprecated—use [JSON.swift](https://github.com/nathanborror/NBKit/blob/master/NBKit/NBKit/JSON.swift).\n* Request.swift is deprecated—use [Alamofire](https://github.com/Alamofire/Alamofire).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanborror%2Fnbkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathanborror%2Fnbkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanborror%2Fnbkit/lists"}