// // AbstractContentViewController.swift // SearchDemo // // Created by Ralf Gronkowski on 13/10/14. // Copyright (c) 2014 Ralf Gronkowski. All rights reserved. // import UIKit import MessageUI class AbstractContentViewController: UIViewController, MFMailComposeViewControllerDelegate { var thisP4FileRev: P4FileRev! let defaultContentInset = UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 0) convenience init( theP4FileRev: P4FileRev ) { self.init() self.thisP4FileRev = theP4FileRev } override func viewDidLoad() { super.viewDidLoad() setupNavigationBar() } func setupNavigationBar() { let doneBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Done, target: self, action: "doneAction") let mailBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Compose, target: self, action: "mailAction") navigationItem.rightBarButtonItems = [ doneBarButtonItem, mailBarButtonItem] } func doneAction() { dismissViewControllerAnimated(true, completion: nil) } func mailAction() { var mailComposer = MFMailComposeViewController() mailComposer.mailComposeDelegate = self mailComposer.setSubject("from P4Searcher") let swarmURL:NSString = NSUserDefaults.standardUserDefaults().stringForKey(SettingsKeys.swarmURLPreferenceKey)! let message = "work on version " + self.thisP4FileRev.rev + " of this in Piper: p4:" + self.thisP4FileRev.file + " or just view the file revision in Swarm: " + swarmURL + "files/" + self.thisP4FileRev.getSwarmURL() mailComposer.setMessageBody(message, isHTML: false) self.presentViewController(mailComposer, animated: true, completion: nil) } func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!){ self.dismissViewControllerAnimated(true, completion: nil) } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 10709 | gronk |
First working example of an iOS app that searches in P4Search and displys content by retrieving it from Swarm. There is a file JSON.swift in the project in which you need to paste some external code from here https://github.com/lingoer/SwiftyJSON/blob/master/SwiftyJSON/SwiftyJSON.swift to simplify JSON parsing. You will also need access to a running P4Search and Swarm instance if you want to run the app on a device or inside an emulator. Coded in Swift with XCode 6.0.1 |