{"id":26172079,"url":"https://github.com/tapwork/wikilocation","last_synced_at":"2025-04-14T20:21:22.135Z","repository":{"id":18208152,"uuid":"21342765","full_name":"tapwork/WikiLocation","owner":"tapwork","description":"WikiLocation - A geolocation based wikipedia app written in Swift","archived":false,"fork":false,"pushed_at":"2014-11-24T14:07:45.000Z","size":387,"stargazers_count":14,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T08:35:41.210Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/tapwork.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":"2014-06-30T07:18:54.000Z","updated_at":"2024-11-23T11:56:43.000Z","dependencies_parsed_at":"2022-08-25T14:51:37.061Z","dependency_job_id":null,"html_url":"https://github.com/tapwork/WikiLocation","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/tapwork%2FWikiLocation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tapwork%2FWikiLocation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tapwork%2FWikiLocation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tapwork%2FWikiLocation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tapwork","download_url":"https://codeload.github.com/tapwork/WikiLocation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248952344,"owners_count":21188427,"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":"2025-03-11T19:53:12.923Z","updated_at":"2025-04-14T20:21:22.116Z","avatar_url":"https://github.com/tapwork.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"WikiLocation\n============\n[![Build Status](http://img.shields.io/travis/tapwork/WikiLocation/master.svg?style=flat)](https://travis-ci.org/tapwork/WikiLocation)\n\n####WikiLocation - A geolocation based wikipedia app written in Swift\n\nThis little app demonstrates how easy it is to create an iOS app with Swift and the new iOS frameworks.\nWhat is this app about? As the name implies, it uses your current location and provides nearby Wikipedia articles. (Buildings, lakes and so on). Straight forward. Not too much magic.\nThis mini app covers ViewControllers, Views \u0026 Models in Swift and custom new iOS Frameworks :\nThere is also a more detailed blog post http://www.cmenschel.de/lets-build-an-app-in-swift about this app.\n###ViewControllers in Swift\nTableViewController with an UITableView: Shows the Wiki articles nearby in a simple list.\nWebViewController with an UIWebView: showing the selected article in a pushed webView\n###New custom iOS Frameworks / modules\n####GeoLocation Manager\nRetrieves the user's location, stops after we got the coordinates. Stops updating location when going into background, refreshes the location when coming into foreground.\nTableViewController observes the location property to load new articles when the location changes.\n####Network Manager\nProvides a model for the WikiArticles, fetches the Wiki articles from the API. Handles the JSON parsing and mapping with our model\n\n### Some Swift patterns\nWhen you start working with Swift you may notice that there are different patterns compared to Objective C.\n####Singleton \n```  Swift\nclass var sharedInstace : GeoManager {\n\tstruct SharedInstance {\n        static let instance = GeoManager()\n        }\n        return SharedInstance.instance\n    }\n}\n```\nThe singleton pattern changes a bit in Swift. We could use the dispatch_once pattern. But a shorter way in Swift is the struct and a static var. At this time Swift does not really provide class variables. XCode 6 says \"Class variables not yet supported\". Looks like that this will come later. But Swift provides type methods. Type methods are equivalent to the class methods + (void)method in Objective C. Structs and enumerations also provides type properties with the static keyword. Type properties can \"store a value that is global to all instances of that type (like a static variable in C).” Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks.\nSo we can go the way with a struct and a read only type property. Swift provides the static keyword in structs which we can use to create to a constant type variable in the struct 'SharedInstance'. The struct is little a helper to enable class typed variables like we know it from C with static. I think the type property and the pattern is still under little construction and will be changed in the near future.\n\n####JSON Parsing \n```  Swift\nvar error:NSError?\nvar jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error:\u0026error) as Dictionary\u003cString,AnyObject\u003e\nvar articles = NSMutableOrderedSet()\nif let jsonarticles = jsonResult[\"articles\"] as? NSArray {\n    for item : AnyObject in jsonarticles {\n\tvar article = WikiArticle(json: item as Dictionary\u003cString, AnyObject\u003e)\n    articles.addObject(article)\n    }\n}\n```\nBecause Swift is strict about types, we need to check and cast a lot. This is one of the biggest differences to Objective C in this example app.\nWe access the ``jsonResult`` via the subscript ``articles`` and check with ``if let`` for the NSArray type (NSJSONSerialization uses Foundation objects).\nIn the for loop we initialize the model object ``WikiArticle`` with a casted Dictionary.\n\n####Variable declaration, initialization and lazy loading\n```  Swift\nclass ViewController: UITableViewController {\n    \n    @lazy var geoManager = GeoManager.sharedInstance\n    var dataSource = WikiArticle[]()\n\n\toverride func viewDidLoad() {\n\t    super.viewDidLoad()\n\n\t    self.geoManager.start()\n\t    self.geoManager.addObserver(self, forKeyPath: \"location\", options: NSKeyValueObservingOptions.New, context: nil)\n\t}\n    .....\n}\n```\nThe ``geoManager`` will be initialized lazy. That means that the instance for the property will be created when we access the property the first time (in viewDidLoad).\nThe dataSource property will be initialized directly.\nInitializing properties in the declaration is new to Objective C developers.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftapwork%2Fwikilocation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftapwork%2Fwikilocation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftapwork%2Fwikilocation/lists"}