Full Code of insidegui/MultipeerDemo for AI

master 448c29215f59 cached
17 files
55.5 KB
15.3k tokens
1 requests
Download .txt
Repository: insidegui/MultipeerDemo
Branch: master
Commit: 448c29215f59
Files: 17
Total size: 55.5 KB

Directory structure:
gitextract_zvrhyaes/

├── .gitignore
├── LICENSE
├── MultipeerDemo/
│   ├── Bootstrap/
│   │   └── AppDelegate.swift
│   ├── Controllers/
│   │   ├── CSOnboardingViewController.swift
│   │   ├── DemoFlowController.swift
│   │   ├── FloatingPictureViewController.swift
│   │   ├── LoadingOverlayViewController.swift
│   │   ├── UIImage+Orientation.swift
│   │   └── UIViewController+Children.swift
│   ├── Core/
│   │   └── PeerService.swift
│   ├── Resources/
│   │   ├── Assets.xcassets/
│   │   │   └── AppIcon.appiconset/
│   │   │       └── Contents.json
│   │   ├── Base.lproj/
│   │   │   └── LaunchScreen.storyboard
│   │   └── Info.plist
│   └── Views/
│       └── CSBigRoundedButton.swift
├── MultipeerDemo.xcodeproj/
│   ├── project.pbxproj
│   └── xcshareddata/
│       └── xcschemes/
│           └── MultipeerDemo.xcscheme
└── README.md

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
.DS_Store
__MACOSX
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.xcworkspace
!default.xcworkspace
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
Crashlytics.sh
generatechangelog.sh
Pods/
Carthage
Provisioning
Crashlytics.sh

================================================
FILE: LICENSE
================================================
Copyright (c) 2017 Guilherme Rambo

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.

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.

================================================
FILE: MultipeerDemo/Bootstrap/AppDelegate.swift
================================================
//
//  AppDelegate.swift
//  MultipeerDemo
//
//  Created by Guilherme Rambo on 23/03/18.
//  Copyright © 2018 Guilherme Rambo. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    private lazy var flowController = DemoFlowController()

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        window = UIWindow()

        window?.rootViewController = flowController

        window?.makeKeyAndVisible()

        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}



================================================
FILE: MultipeerDemo/Controllers/CSOnboardingViewController.swift
================================================
//
//  CSOnboardingViewController.swift
//  CutenessKit
//
//  Created by Guilherme Rambo on 22/02/18.
//  Copyright © 2018 Guilherme Rambo. All rights reserved.
//

import UIKit

open class CSOnboardingViewController: UIViewController {

    private struct Metrics {
        static let buttonSpacing: CGFloat = 14
        static let mainSpacing: CGFloat = 130
        static let titleFontSize: CGFloat = 50
        static let lateralMargin: CGFloat = 30
    }

    public var buttons: [CSBigRoundedButton] = []

    private var buttonActions: [Int: (CSBigRoundedButton) -> Void] = [:]

    public var titleFont: UIFont = UIFont.systemFont(ofSize: Metrics.titleFontSize, weight: .bold) {
        didSet {
            updateTitleLabel()
        }
    }

    public var titleTextColor: UIColor = .white {
        didSet {
            updateTitleLabel()
        }
    }

    public lazy var titleLabel: UILabel = {
        let l = UILabel()

        l.textAlignment = .left
        l.font = titleFont
        l.numberOfLines = 0
        l.lineBreakMode = .byWordWrapping

        return l
    }()

    open override var title: String? {
        didSet {
            updateTitleLabel()
        }
    }

    private func prepareTitleText(with title: String?) -> NSAttributedString? {
        guard let text = title else { return nil }

        let pStyle = NSMutableParagraphStyle()
        pStyle.alignment = titleLabel.textAlignment
        pStyle.lineSpacing = -10

        let kern: CGFloat = -0.55

        let attrs: [NSAttributedString.Key: Any] = [
            .font: titleFont,
            .kern: kern,
            .foregroundColor: titleTextColor,
            .paragraphStyle: pStyle
        ]

        return NSAttributedString(string: text, attributes: attrs)
    }

    private func updateTitleLabel() {
        titleLabel.attributedText = prepareTitleText(with: title)
    }

    @discardableResult func addButton(with title: String, animated: Bool = true, action: @escaping (CSBigRoundedButton) -> Void) -> CSBigRoundedButton {
        let button = CSBigRoundedButton(type: .custom)

        buttons.append(button)
        buttonActions[button.hash] = action

        button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
        button.translatesAutoresizingMaskIntoConstraints = false
        button.setTitle(title, for: .normal)
        button.backgroundColor = #colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1)

        button.alpha = 0
        self.buttonsStackView.addArrangedSubview(button)

        UIView.animate(withDuration: 0.3) {
            self.view.layoutIfNeeded()
        }
        UIView.animate(withDuration: 0.3, delay: 0.25, options: [.beginFromCurrentState, .allowAnimatedContent, .allowUserInteraction], animations: {
            button.alpha = 1
        }, completion: nil)

        return button
    }

    @objc private func buttonAction(_ sender: CSBigRoundedButton) {
        buttonActions[sender.hash]?(sender)
    }

    public lazy var buttonsStackView: UIStackView = {
        let v = UIStackView(arrangedSubviews: [])

        v.axis = .vertical
        v.spacing = Metrics.buttonSpacing

        return v
    }()

    public lazy var mainStackView: UIStackView = {
        let v = UIStackView(arrangedSubviews: [self.titleLabel, self.buttonsStackView])

        v.axis = .vertical
        v.spacing = Metrics.mainSpacing
        v.translatesAutoresizingMaskIntoConstraints = false

        return v
    }()

    open override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)

        view.addSubview(mainStackView)
        mainStackView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
        mainStackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: Metrics.lateralMargin).isActive = true
        mainStackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -Metrics.lateralMargin).isActive = true
    }

}


================================================
FILE: MultipeerDemo/Controllers/DemoFlowController.swift
================================================
//
//  DemoFlowController.swift
//  MultipeerDemo
//
//  Created by Guilherme Rambo on 23/03/18.
//  Copyright © 2018 Guilherme Rambo. All rights reserved.
//

import UIKit
import MobileCoreServices

class DemoFlowController: UIViewController {

    private var isInDemoMode: Bool {
        return UserDefaults.standard.bool(forKey: "DemoMode")
    }

    private lazy var homeViewController: CSOnboardingViewController = {
        let c = CSOnboardingViewController()

        c.title = "Devices"

        return c
    }()

    private lazy var peerService: PeerService = {
        let s = PeerService()

        s.didFindDevice = { [weak self] deviceName in
            self?.homeViewController.addButton(with: deviceName, action: { button in
                self?.didTapDeviceButton(button, for: deviceName)
            })
        }
        s.didReceiveFile = { [weak self] url in
            self?.didReceiveImage(at: url)
        }

        return s
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        installChild(homeViewController)

        if isInDemoMode {
            DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
                self.homeViewController.addButton(with: "iPhone X Rambo", action: { [weak self] button in
                    self?.didTapDeviceButton(button)
                })
            }
            DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
                self.homeViewController.addButton(with: "iPhone 6S", action: { [weak self] button in
                    self?.didTapDeviceButton(button)
                })
            }
        }
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        peerService.startAdvertising()
        peerService.startListening()
    }

    private func didTapDeviceButton(_ button: CSBigRoundedButton, for device: String = "") {
        guard !isInDemoMode else {
            runDemoUpload(for: button)
            return
        }

        transitionIntoConnectingState(for: button)

        peerService.didConnectToDevice = { [weak self] _ in
            self?.showPhotoPicker()
        }

        peerService.connectToDevice(named: device)
    }

    private lazy var photoPickerController: UIImagePickerController = {
        let c = UIImagePickerController()

        c.mediaTypes = [kUTTypeImage as String]
        c.delegate = self

        return c
    }()

    private func showPhotoPicker() {
        present(photoPickerController, animated: true, completion: nil)
    }

    private func runDemoUpload(for button: CSBigRoundedButton) {
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: {
            self.transitionIntoConnectingState(for: button)
            DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
                self.transitionIntoUploadingState()
                DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
                    self.transitionIntoSuccessState()
                })
            })
        })
    }

    private lazy var loadingController = LoadingOverlayViewController()

    private func transitionIntoConnectingState(for button: CSBigRoundedButton) {
        loadingController = LoadingOverlayViewController()
        loadingController.title = "Connecting"

        installChild(loadingController)

        loadingController.animateIn()
    }

    private func transitionIntoUploadingState() {
        loadingController.title = "Uploading"
    }

    private lazy var feedbackGenerator: UINotificationFeedbackGenerator = {
        return UINotificationFeedbackGenerator()
    }()

    private func transitionIntoSuccessState() {
        loadingController.hideSpinner()
        loadingController.title = "Done!"
        
        feedbackGenerator.notificationOccurred(.success)

        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
            self.hideOverlayLoading()
        }
    }

    private func hideOverlayLoading() {
        loadingController.animateOut()
    }

    private func didFinishUpload(with error: Error?) {
        NSLog("Did finish upload. Error: \(String(describing: error))")

        if let error = error {
            loadingController.title = error.localizedDescription
            DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
                self.hideOverlayLoading()
            })
        } else {
            transitionIntoSuccessState()
        }
    }

    private lazy var receivedImageController = FloatingPictureViewController()

    private func didReceiveImage(at url: URL) {
        guard let image = UIImage(contentsOfFile: url.path) else { return }

        receivedImageController = FloatingPictureViewController()

        installChild(receivedImageController)

        receivedImageController.animate(image: image, from: .bottom)
    }

    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }

}

extension DemoFlowController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        dismiss(animated: true, completion: nil)
        hideOverlayLoading()
    }

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
// Local variable inserted by Swift 4.2 migrator.
let info = convertFromUIImagePickerControllerInfoKeyDictionary(info)

        DispatchQueue.main.async {
            self.transitionIntoUploadingState()

            guard let image = info[convertFromUIImagePickerControllerInfoKey(UIImagePickerController.InfoKey.originalImage)] as? UIImage else {
                NSLog("Invalid content!")
                self.hideOverlayLoading()
                return
            }

            guard let pngData = image.withOrientationFixed.pngData() else {
                NSLog("Invalid content!")
                self.hideOverlayLoading()
                return
            }

            self.dismiss(animated: true, completion: nil)

            self.peerService.sendPicture(with: pngData, completion: { [weak self] error in
                self?.didFinishUpload(with: error)
            })
        }
    }

}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromUIImagePickerControllerInfoKeyDictionary(_ input: [UIImagePickerController.InfoKey: Any]) -> [String: Any] {
	return Dictionary(uniqueKeysWithValues: input.map {key, value in (key.rawValue, value)})
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromUIImagePickerControllerInfoKey(_ input: UIImagePickerController.InfoKey) -> String {
	return input.rawValue
}


================================================
FILE: MultipeerDemo/Controllers/FloatingPictureViewController.swift
================================================
//
//  FloatingPictureViewController.swift
//  MultipeerDemo
//
//  Created by Guilherme Rambo on 24/03/18.
//  Copyright © 2018 Guilherme Rambo. All rights reserved.
//

import UIKit

class FloatingPictureViewController: UIViewController {

    enum AnimationOrigin: Int {
        case top
        case bottom
    }

    private lazy var imageView: UIImageView = {
        let v = UIImageView()

        v.translatesAutoresizingMaskIntoConstraints = false
        v.heightAnchor.constraint(lessThanOrEqualToConstant: UIScreen.main.bounds.height - 120).isActive = true
        v.clipsToBounds = true
        v.layer.cornerRadius = 10
        v.contentMode = .scaleAspectFill

        return v
    }()

    private lazy var imageViewCenteringConstraint: NSLayoutConstraint = {
        return imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -UIScreen.main.bounds.height)
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(imageView)

        imageViewCenteringConstraint.isActive = true
        imageView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30).isActive = true
        imageView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -30).isActive = true

        let tap = UITapGestureRecognizer(target: self, action: #selector(hide))
        view.addGestureRecognizer(tap)
    }

    func animate(image: UIImage, from origin: AnimationOrigin) {
        imageView.alpha = 0
        imageView.image = image

        imageViewCenteringConstraint.constant = origin == .bottom ? -UIScreen.main.bounds.height : UIScreen.main.bounds.height

        UIView.animate(withDuration: 0.8, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1.2, options: [.allowAnimatedContent, .beginFromCurrentState], animations: {
            self.imageView.alpha = 1
            self.imageViewCenteringConstraint.constant = 0
            self.view.setNeedsLayout()
            self.view.layoutIfNeeded()
        }, completion: nil)
    }

    @objc func hide() {
        UIView.animate(withDuration: 0.4, animations: {
            self.view.alpha = 0
        }) { _ in
            self.view.removeFromSuperview()
            self.removeFromParent()
        }
    }

}


================================================
FILE: MultipeerDemo/Controllers/LoadingOverlayViewController.swift
================================================
//
//  LoadingOverlayViewController.swift
//  MultipeerDemo
//
//  Created by Guilherme Rambo on 23/03/18.
//  Copyright © 2018 Guilherme Rambo. All rights reserved.
//

import UIKit

class LoadingOverlayViewController: UIViewController {

    private lazy var stackView: UIStackView = {
        let v = UIStackView(arrangedSubviews: [spinner, statusLabel])

        v.axis = .vertical
        v.spacing = 16
        v.translatesAutoresizingMaskIntoConstraints = false

        return v
    }()

    override var title: String? {
        didSet {
            statusLabel.text = title
        }
    }

    private lazy var statusLabel: UILabel = {
        let l = UILabel()

        l.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        l.textColor = UIColor.white.withAlphaComponent(0.8)
        l.numberOfLines = 0
        l.lineBreakMode = .byWordWrapping
        l.textAlignment = .center

        return l
    }()

    private lazy var spinner: UIActivityIndicatorView = {
        return UIActivityIndicatorView(style: .white)
    }()

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        spinner.startAnimating()
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)

        spinner.stopAnimating()
    }

    func animateIn() {
        spinner.startAnimating()

        UIView.animate(withDuration: 0.4) {
            self.view.alpha = 1
        }
    }

    func animateOut() {
        UIView.animate(withDuration: 0.4, animations: {
            self.view.alpha = 0
        }) { _ in
            self.view.removeFromSuperview()
            self.removeFromParent()
        }
    }

    func hideSpinner() {
        UIView.animate(withDuration: 0.4) {
            self.spinner.isHidden = true
            self.spinner.alpha = 0
            self.stackView.setNeedsLayout()
            self.stackView.layoutIfNeeded()
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        view.isOpaque = false
        view.backgroundColor = UIColor.black.withAlphaComponent(0.7)
        view.alpha = 0

        view.addSubview(stackView)
        stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
        stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30).isActive = true
        stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -30).isActive = true
    }

}


================================================
FILE: MultipeerDemo/Controllers/UIImage+Orientation.swift
================================================
//
//  UIImage+Orientation.swift
//  MultipeerDemo
//
//  Created by Guilherme Rambo on 24/03/18.
//  Copyright © 2018 Guilherme Rambo. All rights reserved.
//

import UIKit

extension UIImage {

    var withOrientationFixed: UIImage {
        guard imageOrientation != .up else { return self }

        UIGraphicsBeginImageContextWithOptions(size, false, scale)
        draw(in: CGRect(origin: .zero, size: size))

        guard let fixedImage = UIGraphicsGetImageFromCurrentImageContext() else {
            fatalError("Failed to get image from CGContext!")
        }

        UIGraphicsEndImageContext()

        return fixedImage
    }

}


================================================
FILE: MultipeerDemo/Controllers/UIViewController+Children.swift
================================================
//
//  UIViewController+Children.swift
//  MultipeerDemo
//
//  Created by Guilherme Rambo on 23/03/18.
//  Copyright © 2018 Guilherme Rambo. All rights reserved.
//

import UIKit

extension UIViewController {

    func installChild(_ controller: UIViewController) {
        addChild(controller)
        controller.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        controller.view.frame = view.bounds
        view.addSubview(controller.view)
        controller.didMove(toParent: self)
    }

}


================================================
FILE: MultipeerDemo/Core/PeerService.swift
================================================
//
//  PeerService.swift
//  MultipeerDemo
//
//  Created by Guilherme Rambo on 23/03/18.
//  Copyright © 2018 Guilherme Rambo. All rights reserved.
//

import UIKit
import MultipeerConnectivity

final class PeerService: NSObject {

    var didFindDevice: ((_ name: String) -> Void)?

    var didConnectToDevice: ((_ name: String) -> Void)?

    var didReceiveFile: ((_ url: URL) -> Void)?

    // MD1
    lazy var me: MCPeerID = {
        let peer: MCPeerID

        if let peerData = UserDefaults.standard.data(forKey: "mePeerID") {
            guard let unarchivedPeer = NSKeyedUnarchiver.unarchiveObject(with: peerData) as? MCPeerID else {
                fatalError("mePeerID in user defaults is not a MCPeerID. WHAT?")
            }

            peer = unarchivedPeer
        } else {
            peer = MCPeerID(displayName: UIDevice.current.name)

            let peerData = NSKeyedArchiver.archivedData(withRootObject: peer)
            UserDefaults.standard.set(peerData, forKey: "mePeerID")
            UserDefaults.standard.synchronize()
        }

        return peer
    }()

    // MD2
    lazy var session: MCSession = {
        let s = MCSession(peer: me, securityIdentity: nil, encryptionPreference: .none)

        s.delegate = self

        return s
    }()

    // MD4
    lazy var advertiser: MCNearbyServiceAdvertiser = {
        let a = MCNearbyServiceAdvertiser(peer: me, discoveryInfo: ["demo": "data"], serviceType: "MultipeerDemo")

        a.delegate = self

        return a
    }()

    // MD7
    lazy var browser: MCNearbyServiceBrowser = {
        let b = MCNearbyServiceBrowser(peer: me, serviceType: "MultipeerDemo")

        b.delegate = self

        return b
    }()

    func startAdvertising() {
        // MD6
        advertiser.startAdvertisingPeer()
    }

    func startListening() {
        // MD9
        browser.startBrowsingForPeers()
    }

    private var devices: [String: MCPeerID] = [:]

    func connectToDevice(named name: String) {
        // MD10
        guard let peer = devices[name] else { return }

        guard !session.connectedPeers.contains(peer) else {
            didConnectToDevice?(peer.displayName)
            return
        }

        browser.invitePeer(peer, to: session, withContext: nil, timeout: 10)
    }

    func sendPicture(with data: Data, completion: @escaping (Error?) -> Void) {
        // MD11
        guard let peer = session.connectedPeers.last else {
            NSLog("No connected peers to send to")
            return
        }

        guard let baseURL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first else {
            fatalError("No caches directory. WHAT?!")
        }

        let filename = UUID().uuidString + ".png"

        let fileURL = baseURL.appendingPathComponent(filename)

        do {
            try data.write(to: fileURL, options: .atomicWrite)

            session.sendResource(at: fileURL,
                                 withName: filename,
                                 toPeer: peer,
                                 withCompletionHandler: completion)
        } catch {
            completion(error)
        }
    }

}

// MD8
extension PeerService: MCNearbyServiceBrowserDelegate {

    func browser(_ browser: MCNearbyServiceBrowser, foundPeer peerID: MCPeerID, withDiscoveryInfo info: [String : String]?) {
        guard devices[peerID.displayName] == nil else { return }

        devices[peerID.displayName] = peerID

        DispatchQueue.main.async {
            self.didFindDevice?(peerID.displayName)
        }
    }

    func browser(_ browser: MCNearbyServiceBrowser, lostPeer peerID: MCPeerID) {
        NSLog("Puke")
    }

}

// MD5
extension PeerService: MCNearbyServiceAdvertiserDelegate {

    func advertiser(_ advertiser: MCNearbyServiceAdvertiser, didReceiveInvitationFromPeer peerID: MCPeerID, withContext context: Data?, invitationHandler: @escaping (Bool, MCSession?) -> Void) {
        // This is insecure! We should verify that the peer is valid and etc etc
        invitationHandler(true, session)
    }

    func advertiser(_ advertiser: MCNearbyServiceAdvertiser, didNotStartAdvertisingPeer error: Error) {
        NSLog("Woops! Advertising failed with error \(String(describing: error))")
    }

}

// MD3
extension PeerService: MCSessionDelegate {

    func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) {
        switch state {
        case .connected:
            print("Now connected to \(peerID.displayName)")
            DispatchQueue.main.async {
                self.didConnectToDevice?(peerID.displayName)
            }
        case .connecting:
            print("Connecting to \(peerID.displayName)")
        case .notConnected:
            print("NOT connected to \(peerID.displayName)")
        @unknown default:
            print("Unknown state \(state)")
        }
    }

    func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) {

    }

    func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID) {

    }

    func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress) {
        NSLog("Started resource download: \(resourceName)")
    }

    func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL?, withError error: Error?) {
        NSLog("Finished resource download: \(resourceName)")

        // MD12
        guard let url = localURL else { return }

        DispatchQueue.main.async {
            self.didReceiveFile?(url)
        }
    }

}


================================================
FILE: MultipeerDemo/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json
================================================
{
  "images" : [
    {
      "idiom" : "iphone",
      "size" : "20x20",
      "scale" : "2x"
    },
    {
      "idiom" : "iphone",
      "size" : "20x20",
      "scale" : "3x"
    },
    {
      "idiom" : "iphone",
      "size" : "29x29",
      "scale" : "2x"
    },
    {
      "idiom" : "iphone",
      "size" : "29x29",
      "scale" : "3x"
    },
    {
      "idiom" : "iphone",
      "size" : "40x40",
      "scale" : "2x"
    },
    {
      "idiom" : "iphone",
      "size" : "40x40",
      "scale" : "3x"
    },
    {
      "idiom" : "iphone",
      "size" : "60x60",
      "scale" : "2x"
    },
    {
      "idiom" : "iphone",
      "size" : "60x60",
      "scale" : "3x"
    },
    {
      "idiom" : "ipad",
      "size" : "20x20",
      "scale" : "1x"
    },
    {
      "idiom" : "ipad",
      "size" : "20x20",
      "scale" : "2x"
    },
    {
      "idiom" : "ipad",
      "size" : "29x29",
      "scale" : "1x"
    },
    {
      "idiom" : "ipad",
      "size" : "29x29",
      "scale" : "2x"
    },
    {
      "idiom" : "ipad",
      "size" : "40x40",
      "scale" : "1x"
    },
    {
      "idiom" : "ipad",
      "size" : "40x40",
      "scale" : "2x"
    },
    {
      "idiom" : "ipad",
      "size" : "76x76",
      "scale" : "1x"
    },
    {
      "idiom" : "ipad",
      "size" : "76x76",
      "scale" : "2x"
    },
    {
      "idiom" : "ipad",
      "size" : "83.5x83.5",
      "scale" : "2x"
    }
  ],
  "info" : {
    "version" : 1,
    "author" : "xcode"
  }
}

================================================
FILE: MultipeerDemo/Resources/Base.lproj/LaunchScreen.storyboard
================================================
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
    <device id="retina4_7" orientation="portrait">
        <adaptation id="fullscreen"/>
    </device>
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <scenes>
        <!--View Controller-->
        <scene sceneID="EHf-IW-A2E">
            <objects>
                <viewController id="01J-lp-oVM" sceneMemberID="viewController">
                    <view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
                        <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
                        <viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
                    </view>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="53" y="375"/>
        </scene>
    </scenes>
</document>


================================================
FILE: MultipeerDemo/Resources/Info.plist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>$(DEVELOPMENT_LANGUAGE)</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0</string>
	<key>CFBundleVersion</key>
	<string>1</string>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>NSPhotoLibraryUsageDescription</key>
	<string>Send pictures to other devices</string>
	<key>UILaunchStoryboardName</key>
	<string>LaunchScreen</string>
	<key>UIRequiredDeviceCapabilities</key>
	<array>
		<string>armv7</string>
	</array>
	<key>UIStatusBarStyle</key>
	<string>UIStatusBarStyleLightContent</string>
	<key>UISupportedInterfaceOrientations</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
	</array>
	<key>UISupportedInterfaceOrientations~ipad</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationPortraitUpsideDown</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
</dict>
</plist>


================================================
FILE: MultipeerDemo/Views/CSBigRoundedButton.swift
================================================
//
//  CSBigRoundedButton.swift
//  CutenessKit
//
//  Created by Guilherme Rambo on 22/02/18.
//  Copyright © 2018 Guilherme Rambo. All rights reserved.
//

import UIKit

open class CSBigRoundedButton: UIButton {

    public enum HighlightStyle: Int {
        case darker
        case lighter
    }

    public var highlightStyle: HighlightStyle = .darker {
        didSet {
            guard highlightStyle != oldValue else { return }

            updateHighlightLayerBackground()
        }
    }

    private struct Metrics {
        static let height: CGFloat = 47
        static let cornerRadius: CGFloat = 11

        struct Animation {
            static let highlightDuration: TimeInterval = 0.3
            static let bounceDurationIn: TimeInterval = 0.6
            static let bounceDurationOut: TimeInterval = 0.8
            static let springVelocity: CGFloat = 1.2
            static let springDamping: CGFloat = 0.4
        }
    }

    public var titleFont: UIFont = UIFont.systemFont(ofSize: 16, weight: .medium)

    public var cornerRadius: CGFloat = Metrics.cornerRadius {
        didSet {
            setNeedsLayout()
        }
    }

    public var bounces = true

    private var _backgroundColor: UIColor?

    open override var backgroundColor: UIColor? {
        get {
            return _backgroundColor
        }
        set {
            _backgroundColor = newValue

            updateAppearance()
        }
    }

    public override init(frame: CGRect) {
        super.init(frame: frame)

        setup()
    }

    public required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        setup()
    }

    open override func layoutSubviews() {
        super.layoutSubviews()

        updateAppearance()
    }

    private lazy var backgroundLayer: CALayer = CALayer()

    private lazy var highlightLayer: CALayer = {
        let l = CALayer()

        l.opacity = 0

        return l
    }()

    private var customizedFont = false

    private func setup() {
        backgroundLayer.addSublayer(highlightLayer)

        setTitleColor(.white, for: .normal)

        layer.addSublayer(backgroundLayer)

        updateAppearance()

        addTarget(self,
                  action: #selector(transitionIntoHighlightedAppearance),
                  for: [.touchDown, .touchDragEnter])

        addTarget(self,
                  action: #selector(transitionIntoNormalAppearance),
                  for: [.touchUpInside, .touchDragExit, .touchUpOutside])

        updateHighlightLayerBackground()
    }

    private func updateAppearance() {
        backgroundLayer.zPosition = 1

        titleLabel?.layer.zPosition = 2
        titleLabel?.font = titleFont

        backgroundLayer.masksToBounds = true
        backgroundLayer.cornerRadius = cornerRadius
        backgroundLayer.frame = layer.bounds
        backgroundLayer.backgroundColor = backgroundColor?.cgColor

        highlightLayer.frame = layer.bounds
    }

    private func updateHighlightLayerBackground() {
        switch highlightStyle {
        case .lighter:
            highlightLayer.backgroundColor = UIColor.white.withAlphaComponent(0.15).cgColor
        case .darker:
            highlightLayer.backgroundColor = UIColor.black.withAlphaComponent(0.2).cgColor
        }
    }

    open override var intrinsicContentSize: CGSize {
        return CGSize(width: UIView.noIntrinsicMetric, height: Metrics.height)
    }

    private let animationOptions: UIView.AnimationOptions = [
        .beginFromCurrentState,
        .allowAnimatedContent,
        .allowUserInteraction
    ]

    @objc private func transitionIntoHighlightedAppearance() {
        UIView.animate(withDuration: Metrics.Animation.highlightDuration,
                       delay: 0,
                       options: animationOptions,
                       animations:
            {
                self.highlightLayer.opacity = 1
        }, completion: nil)

        bounceInIfNeeded()
    }

    private func bounceInIfNeeded() {
        guard bounces else { return }

        UIView.animate(withDuration: Metrics.Animation.bounceDurationIn,
                       delay: 0, usingSpringWithDamping: Metrics.Animation.springDamping,
                       initialSpringVelocity: Metrics.Animation.springVelocity,
                       options: animationOptions,
                       animations:
            {
                self.layer.transform = CATransform3DMakeScale(0.95, 0.95, 1)
        }, completion: nil)
    }

    @objc private func transitionIntoNormalAppearance() {
        UIView.animate(withDuration: Metrics.Animation.highlightDuration,
                       delay: 0,
                       options: animationOptions,
                       animations:
            {
                self.highlightLayer.opacity = 0
        }, completion: nil)

        bounceOutIfNeeded()
    }

    private func bounceOutIfNeeded() {
        guard bounces else { return }

        UIView.animate(withDuration: Metrics.Animation.bounceDurationOut,
                       delay: 0, usingSpringWithDamping: Metrics.Animation.springDamping,
                       initialSpringVelocity: Metrics.Animation.springVelocity,
                       options: animationOptions,
                       animations:
            {
                self.layer.transform = CATransform3DIdentity
        }, completion: nil)
    }

}


================================================
FILE: MultipeerDemo.xcodeproj/project.pbxproj
================================================
// !$*UTF8*$!
{
	archiveVersion = 1;
	classes = {
	};
	objectVersion = 48;
	objects = {

/* Begin PBXBuildFile section */
		DD02F68C2065B1A6003D8E64 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD02F68B2065B1A6003D8E64 /* AppDelegate.swift */; };
		DD02F6932065B1A6003D8E64 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DD02F6922065B1A6003D8E64 /* Assets.xcassets */; };
		DD02F6962065B1A6003D8E64 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DD02F6942065B1A6003D8E64 /* LaunchScreen.storyboard */; };
		DD02F6A22065B1E4003D8E64 /* CSBigRoundedButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD02F6A12065B1E4003D8E64 /* CSBigRoundedButton.swift */; };
		DDAC10322066063F008EE2C1 /* FloatingPictureViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAC10312066063F008EE2C1 /* FloatingPictureViewController.swift */; };
		DDAC1034206609E6008EE2C1 /* UIImage+Orientation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAC1033206609E6008EE2C1 /* UIImage+Orientation.swift */; };
		DDF978BC2065B27800637CC9 /* CSOnboardingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDF978BB2065B27800637CC9 /* CSOnboardingViewController.swift */; };
		DDF978BE2065B2C600637CC9 /* DemoFlowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDF978BD2065B2C600637CC9 /* DemoFlowController.swift */; };
		DDF978C02065B84500637CC9 /* LoadingOverlayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDF978BF2065B84500637CC9 /* LoadingOverlayViewController.swift */; };
		DDF978C22065BC7000637CC9 /* UIViewController+Children.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDF978C12065BC7000637CC9 /* UIViewController+Children.swift */; };
		DDF978C52065CC2E00637CC9 /* PeerService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDF978C42065CC2E00637CC9 /* PeerService.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
		DD02F6882065B1A6003D8E64 /* MultipeerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MultipeerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
		DD02F68B2065B1A6003D8E64 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
		DD02F6922065B1A6003D8E64 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
		DD02F6952065B1A6003D8E64 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
		DD02F6972065B1A6003D8E64 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
		DD02F6A12065B1E4003D8E64 /* CSBigRoundedButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSBigRoundedButton.swift; sourceTree = "<group>"; };
		DDAC10312066063F008EE2C1 /* FloatingPictureViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FloatingPictureViewController.swift; sourceTree = "<group>"; };
		DDAC1033206609E6008EE2C1 /* UIImage+Orientation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Orientation.swift"; sourceTree = "<group>"; };
		DDF978BB2065B27800637CC9 /* CSOnboardingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSOnboardingViewController.swift; sourceTree = "<group>"; };
		DDF978BD2065B2C600637CC9 /* DemoFlowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoFlowController.swift; sourceTree = "<group>"; };
		DDF978BF2065B84500637CC9 /* LoadingOverlayViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingOverlayViewController.swift; sourceTree = "<group>"; };
		DDF978C12065BC7000637CC9 /* UIViewController+Children.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Children.swift"; sourceTree = "<group>"; };
		DDF978C42065CC2E00637CC9 /* PeerService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PeerService.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
		DD02F6852065B1A6003D8E64 /* Frameworks */ = {
			isa = PBXFrameworksBuildPhase;
			buildActionMask = 2147483647;
			files = (
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
		DD02F67F2065B1A6003D8E64 = {
			isa = PBXGroup;
			children = (
				DD02F68A2065B1A6003D8E64 /* MultipeerDemo */,
				DD02F6892065B1A6003D8E64 /* Products */,
			);
			sourceTree = "<group>";
		};
		DD02F6892065B1A6003D8E64 /* Products */ = {
			isa = PBXGroup;
			children = (
				DD02F6882065B1A6003D8E64 /* MultipeerDemo.app */,
			);
			name = Products;
			sourceTree = "<group>";
		};
		DD02F68A2065B1A6003D8E64 /* MultipeerDemo */ = {
			isa = PBXGroup;
			children = (
				DDF978C32065CC0100637CC9 /* Core */,
				DD02F6A02065B1B9003D8E64 /* Resources */,
				DD02F69F2065B1B5003D8E64 /* Views */,
				DD02F69E2065B1B0003D8E64 /* Bootstrap */,
				DD02F69D2065B1AC003D8E64 /* Controllers */,
			);
			path = MultipeerDemo;
			sourceTree = "<group>";
		};
		DD02F69D2065B1AC003D8E64 /* Controllers */ = {
			isa = PBXGroup;
			children = (
				DDF978C12065BC7000637CC9 /* UIViewController+Children.swift */,
				DDAC1033206609E6008EE2C1 /* UIImage+Orientation.swift */,
				DDF978BB2065B27800637CC9 /* CSOnboardingViewController.swift */,
				DDF978BF2065B84500637CC9 /* LoadingOverlayViewController.swift */,
				DDAC10312066063F008EE2C1 /* FloatingPictureViewController.swift */,
				DDF978BD2065B2C600637CC9 /* DemoFlowController.swift */,
			);
			path = Controllers;
			sourceTree = "<group>";
		};
		DD02F69E2065B1B0003D8E64 /* Bootstrap */ = {
			isa = PBXGroup;
			children = (
				DD02F68B2065B1A6003D8E64 /* AppDelegate.swift */,
			);
			path = Bootstrap;
			sourceTree = "<group>";
		};
		DD02F69F2065B1B5003D8E64 /* Views */ = {
			isa = PBXGroup;
			children = (
				DD02F6A12065B1E4003D8E64 /* CSBigRoundedButton.swift */,
			);
			path = Views;
			sourceTree = "<group>";
		};
		DD02F6A02065B1B9003D8E64 /* Resources */ = {
			isa = PBXGroup;
			children = (
				DD02F6922065B1A6003D8E64 /* Assets.xcassets */,
				DD02F6942065B1A6003D8E64 /* LaunchScreen.storyboard */,
				DD02F6972065B1A6003D8E64 /* Info.plist */,
			);
			path = Resources;
			sourceTree = "<group>";
		};
		DDF978C32065CC0100637CC9 /* Core */ = {
			isa = PBXGroup;
			children = (
				DDF978C42065CC2E00637CC9 /* PeerService.swift */,
			);
			path = Core;
			sourceTree = "<group>";
		};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
		DD02F6872065B1A6003D8E64 /* MultipeerDemo */ = {
			isa = PBXNativeTarget;
			buildConfigurationList = DD02F69A2065B1A6003D8E64 /* Build configuration list for PBXNativeTarget "MultipeerDemo" */;
			buildPhases = (
				DD02F6842065B1A6003D8E64 /* Sources */,
				DD02F6852065B1A6003D8E64 /* Frameworks */,
				DD02F6862065B1A6003D8E64 /* Resources */,
			);
			buildRules = (
			);
			dependencies = (
			);
			name = MultipeerDemo;
			productName = MultipeerDemo;
			productReference = DD02F6882065B1A6003D8E64 /* MultipeerDemo.app */;
			productType = "com.apple.product-type.application";
		};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
		DD02F6802065B1A6003D8E64 /* Project object */ = {
			isa = PBXProject;
			attributes = {
				LastSwiftUpdateCheck = 0920;
				LastUpgradeCheck = 1030;
				ORGANIZATIONNAME = "Guilherme Rambo";
				TargetAttributes = {
					DD02F6872065B1A6003D8E64 = {
						CreatedOnToolsVersion = 9.2;
						LastSwiftMigration = 1030;
						ProvisioningStyle = Automatic;
					};
				};
			};
			buildConfigurationList = DD02F6832065B1A6003D8E64 /* Build configuration list for PBXProject "MultipeerDemo" */;
			compatibilityVersion = "Xcode 8.0";
			developmentRegion = en;
			hasScannedForEncodings = 0;
			knownRegions = (
				en,
				Base,
			);
			mainGroup = DD02F67F2065B1A6003D8E64;
			productRefGroup = DD02F6892065B1A6003D8E64 /* Products */;
			projectDirPath = "";
			projectRoot = "";
			targets = (
				DD02F6872065B1A6003D8E64 /* MultipeerDemo */,
			);
		};
/* End PBXProject section */

/* Begin PBXResourcesBuildPhase section */
		DD02F6862065B1A6003D8E64 /* Resources */ = {
			isa = PBXResourcesBuildPhase;
			buildActionMask = 2147483647;
			files = (
				DD02F6962065B1A6003D8E64 /* LaunchScreen.storyboard in Resources */,
				DD02F6932065B1A6003D8E64 /* Assets.xcassets in Resources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
		DD02F6842065B1A6003D8E64 /* Sources */ = {
			isa = PBXSourcesBuildPhase;
			buildActionMask = 2147483647;
			files = (
				DDF978C52065CC2E00637CC9 /* PeerService.swift in Sources */,
				DDF978BE2065B2C600637CC9 /* DemoFlowController.swift in Sources */,
				DDF978C22065BC7000637CC9 /* UIViewController+Children.swift in Sources */,
				DD02F6A22065B1E4003D8E64 /* CSBigRoundedButton.swift in Sources */,
				DDF978BC2065B27800637CC9 /* CSOnboardingViewController.swift in Sources */,
				DDAC10322066063F008EE2C1 /* FloatingPictureViewController.swift in Sources */,
				DD02F68C2065B1A6003D8E64 /* AppDelegate.swift in Sources */,
				DDF978C02065B84500637CC9 /* LoadingOverlayViewController.swift in Sources */,
				DDAC1034206609E6008EE2C1 /* UIImage+Orientation.swift in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
		DD02F6942065B1A6003D8E64 /* LaunchScreen.storyboard */ = {
			isa = PBXVariantGroup;
			children = (
				DD02F6952065B1A6003D8E64 /* Base */,
			);
			name = LaunchScreen.storyboard;
			sourceTree = "<group>";
		};
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
		DD02F6982065B1A6003D8E64 /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ALWAYS_SEARCH_USER_PATHS = NO;
				CLANG_ANALYZER_NONNULL = YES;
				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
				CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
				CLANG_CXX_LIBRARY = "libc++";
				CLANG_ENABLE_MODULES = YES;
				CLANG_ENABLE_OBJC_ARC = YES;
				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
				CLANG_WARN_BOOL_CONVERSION = YES;
				CLANG_WARN_COMMA = YES;
				CLANG_WARN_CONSTANT_CONVERSION = YES;
				CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
				CLANG_WARN_EMPTY_BODY = YES;
				CLANG_WARN_ENUM_CONVERSION = YES;
				CLANG_WARN_INFINITE_RECURSION = YES;
				CLANG_WARN_INT_CONVERSION = YES;
				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
				CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
				CLANG_WARN_STRICT_PROTOTYPES = YES;
				CLANG_WARN_SUSPICIOUS_MOVE = YES;
				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
				CLANG_WARN_UNREACHABLE_CODE = YES;
				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
				CODE_SIGN_IDENTITY = "iPhone Developer";
				COPY_PHASE_STRIP = NO;
				DEBUG_INFORMATION_FORMAT = dwarf;
				ENABLE_STRICT_OBJC_MSGSEND = YES;
				ENABLE_TESTABILITY = YES;
				GCC_C_LANGUAGE_STANDARD = gnu11;
				GCC_DYNAMIC_NO_PIC = NO;
				GCC_NO_COMMON_BLOCKS = YES;
				GCC_OPTIMIZATION_LEVEL = 0;
				GCC_PREPROCESSOR_DEFINITIONS = (
					"DEBUG=1",
					"$(inherited)",
				);
				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
				GCC_WARN_UNDECLARED_SELECTOR = YES;
				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
				GCC_WARN_UNUSED_FUNCTION = YES;
				GCC_WARN_UNUSED_VARIABLE = YES;
				IPHONEOS_DEPLOYMENT_TARGET = 11.2;
				MTL_ENABLE_DEBUG_INFO = YES;
				ONLY_ACTIVE_ARCH = YES;
				SDKROOT = iphoneos;
				SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
			};
			name = Debug;
		};
		DD02F6992065B1A6003D8E64 /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ALWAYS_SEARCH_USER_PATHS = NO;
				CLANG_ANALYZER_NONNULL = YES;
				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
				CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
				CLANG_CXX_LIBRARY = "libc++";
				CLANG_ENABLE_MODULES = YES;
				CLANG_ENABLE_OBJC_ARC = YES;
				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
				CLANG_WARN_BOOL_CONVERSION = YES;
				CLANG_WARN_COMMA = YES;
				CLANG_WARN_CONSTANT_CONVERSION = YES;
				CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
				CLANG_WARN_EMPTY_BODY = YES;
				CLANG_WARN_ENUM_CONVERSION = YES;
				CLANG_WARN_INFINITE_RECURSION = YES;
				CLANG_WARN_INT_CONVERSION = YES;
				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
				CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
				CLANG_WARN_STRICT_PROTOTYPES = YES;
				CLANG_WARN_SUSPICIOUS_MOVE = YES;
				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
				CLANG_WARN_UNREACHABLE_CODE = YES;
				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
				CODE_SIGN_IDENTITY = "iPhone Developer";
				COPY_PHASE_STRIP = NO;
				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
				ENABLE_NS_ASSERTIONS = NO;
				ENABLE_STRICT_OBJC_MSGSEND = YES;
				GCC_C_LANGUAGE_STANDARD = gnu11;
				GCC_NO_COMMON_BLOCKS = YES;
				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
				GCC_WARN_UNDECLARED_SELECTOR = YES;
				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
				GCC_WARN_UNUSED_FUNCTION = YES;
				GCC_WARN_UNUSED_VARIABLE = YES;
				IPHONEOS_DEPLOYMENT_TARGET = 11.2;
				MTL_ENABLE_DEBUG_INFO = NO;
				SDKROOT = iphoneos;
				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
				VALIDATE_PRODUCT = YES;
			};
			name = Release;
		};
		DD02F69B2065B1A6003D8E64 /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
				CODE_SIGN_STYLE = Automatic;
				DEVELOPMENT_TEAM = 8C7439RJLG;
				INFOPLIST_FILE = MultipeerDemo/Resources/Info.plist;
				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
				PRODUCT_BUNDLE_IDENTIFIER = br.com.guilhermerambo.MultipeerDemo;
				PRODUCT_NAME = "$(TARGET_NAME)";
				SWIFT_VERSION = 5.0;
				TARGETED_DEVICE_FAMILY = "1,2";
			};
			name = Debug;
		};
		DD02F69C2065B1A6003D8E64 /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
				CODE_SIGN_STYLE = Automatic;
				DEVELOPMENT_TEAM = 8C7439RJLG;
				INFOPLIST_FILE = MultipeerDemo/Resources/Info.plist;
				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
				PRODUCT_BUNDLE_IDENTIFIER = br.com.guilhermerambo.MultipeerDemo;
				PRODUCT_NAME = "$(TARGET_NAME)";
				SWIFT_VERSION = 5.0;
				TARGETED_DEVICE_FAMILY = "1,2";
			};
			name = Release;
		};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
		DD02F6832065B1A6003D8E64 /* Build configuration list for PBXProject "MultipeerDemo" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				DD02F6982065B1A6003D8E64 /* Debug */,
				DD02F6992065B1A6003D8E64 /* Release */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Release;
		};
		DD02F69A2065B1A6003D8E64 /* Build configuration list for PBXNativeTarget "MultipeerDemo" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				DD02F69B2065B1A6003D8E64 /* Debug */,
				DD02F69C2065B1A6003D8E64 /* Release */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Release;
		};
/* End XCConfigurationList section */
	};
	rootObject = DD02F6802065B1A6003D8E64 /* Project object */;
}


================================================
FILE: MultipeerDemo.xcodeproj/xcshareddata/xcschemes/MultipeerDemo.xcscheme
================================================
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
   LastUpgradeVersion = "1030"
   version = "1.3">
   <BuildAction
      parallelizeBuildables = "YES"
      buildImplicitDependencies = "YES">
      <BuildActionEntries>
         <BuildActionEntry
            buildForTesting = "YES"
            buildForRunning = "YES"
            buildForProfiling = "YES"
            buildForArchiving = "YES"
            buildForAnalyzing = "YES">
            <BuildableReference
               BuildableIdentifier = "primary"
               BlueprintIdentifier = "DD02F6872065B1A6003D8E64"
               BuildableName = "MultipeerDemo.app"
               BlueprintName = "MultipeerDemo"
               ReferencedContainer = "container:MultipeerDemo.xcodeproj">
            </BuildableReference>
         </BuildActionEntry>
      </BuildActionEntries>
   </BuildAction>
   <TestAction
      buildConfiguration = "Debug"
      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
      shouldUseLaunchSchemeArgsEnv = "YES">
      <Testables>
      </Testables>
      <MacroExpansion>
         <BuildableReference
            BuildableIdentifier = "primary"
            BlueprintIdentifier = "DD02F6872065B1A6003D8E64"
            BuildableName = "MultipeerDemo.app"
            BlueprintName = "MultipeerDemo"
            ReferencedContainer = "container:MultipeerDemo.xcodeproj">
         </BuildableReference>
      </MacroExpansion>
      <AdditionalOptions>
      </AdditionalOptions>
   </TestAction>
   <LaunchAction
      buildConfiguration = "Debug"
      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
      launchStyle = "0"
      useCustomWorkingDirectory = "NO"
      ignoresPersistentStateOnLaunch = "NO"
      debugDocumentVersioning = "YES"
      debugServiceExtension = "internal"
      allowLocationSimulation = "YES">
      <BuildableProductRunnable
         runnableDebuggingMode = "0">
         <BuildableReference
            BuildableIdentifier = "primary"
            BlueprintIdentifier = "DD02F6872065B1A6003D8E64"
            BuildableName = "MultipeerDemo.app"
            BlueprintName = "MultipeerDemo"
            ReferencedContainer = "container:MultipeerDemo.xcodeproj">
         </BuildableReference>
      </BuildableProductRunnable>
      <CommandLineArguments>
         <CommandLineArgument
            argument = "-DemoMode YES"
            isEnabled = "NO">
         </CommandLineArgument>
      </CommandLineArguments>
      <AdditionalOptions>
      </AdditionalOptions>
   </LaunchAction>
   <ProfileAction
      buildConfiguration = "Release"
      shouldUseLaunchSchemeArgsEnv = "YES"
      savedToolIdentifier = ""
      useCustomWorkingDirectory = "NO"
      debugDocumentVersioning = "YES">
      <BuildableProductRunnable
         runnableDebuggingMode = "0">
         <BuildableReference
            BuildableIdentifier = "primary"
            BlueprintIdentifier = "DD02F6872065B1A6003D8E64"
            BuildableName = "MultipeerDemo.app"
            BlueprintName = "MultipeerDemo"
            ReferencedContainer = "container:MultipeerDemo.xcodeproj">
         </BuildableReference>
      </BuildableProductRunnable>
   </ProfileAction>
   <AnalyzeAction
      buildConfiguration = "Debug">
   </AnalyzeAction>
   <ArchiveAction
      buildConfiguration = "Release"
      revealArchiveInOrganizer = "YES">
   </ArchiveAction>
</Scheme>


================================================
FILE: README.md
================================================
# MultipeerDemo

A sample app showing how to transfer files between two devices using [MultipeerConnectivity](https://developer.apple.com/documentation/multipeerconnectivity).

This sample app is part of my talk on MultipeerConnectivity, you can get the [slides in Portuguese](GuilhermeRambo-MultipeerConnectivity-pt.pdf) and [in English](./GuilhermeRambo-MultipeerConnectivity-en.pdf).

![GIF shows a device sending a picture to another device over the air](./demo.gif)
Download .txt
gitextract_zvrhyaes/

├── .gitignore
├── LICENSE
├── MultipeerDemo/
│   ├── Bootstrap/
│   │   └── AppDelegate.swift
│   ├── Controllers/
│   │   ├── CSOnboardingViewController.swift
│   │   ├── DemoFlowController.swift
│   │   ├── FloatingPictureViewController.swift
│   │   ├── LoadingOverlayViewController.swift
│   │   ├── UIImage+Orientation.swift
│   │   └── UIViewController+Children.swift
│   ├── Core/
│   │   └── PeerService.swift
│   ├── Resources/
│   │   ├── Assets.xcassets/
│   │   │   └── AppIcon.appiconset/
│   │   │       └── Contents.json
│   │   ├── Base.lproj/
│   │   │   └── LaunchScreen.storyboard
│   │   └── Info.plist
│   └── Views/
│       └── CSBigRoundedButton.swift
├── MultipeerDemo.xcodeproj/
│   ├── project.pbxproj
│   └── xcshareddata/
│       └── xcschemes/
│           └── MultipeerDemo.xcscheme
└── README.md
Condensed preview — 17 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (62K chars).
[
  {
    "path": ".gitignore",
    "chars": 304,
    "preview": ".DS_Store\n__MACOSX\n*.pbxuser\n!default.pbxuser\n*.mode1v3\n!default.mode1v3\n*.mode2v3\n!default.mode2v3\n*.perspectivev3\n!def"
  },
  {
    "path": "LICENSE",
    "chars": 1276,
    "preview": "Copyright (c) 2017 Guilherme Rambo\n\nRedistribution and use in source and binary forms, with or without\nmodification, are"
  },
  {
    "path": "MultipeerDemo/Bootstrap/AppDelegate.swift",
    "chars": 2294,
    "preview": "//\n//  AppDelegate.swift\n//  MultipeerDemo\n//\n//  Created by Guilherme Rambo on 23/03/18.\n//  Copyright © 2018 Guilherme"
  },
  {
    "path": "MultipeerDemo/Controllers/CSOnboardingViewController.swift",
    "chars": 4054,
    "preview": "//\n//  CSOnboardingViewController.swift\n//  CutenessKit\n//\n//  Created by Guilherme Rambo on 22/02/18.\n//  Copyright © 2"
  },
  {
    "path": "MultipeerDemo/Controllers/DemoFlowController.swift",
    "chars": 6741,
    "preview": "//\n//  DemoFlowController.swift\n//  MultipeerDemo\n//\n//  Created by Guilherme Rambo on 23/03/18.\n//  Copyright © 2018 Gu"
  },
  {
    "path": "MultipeerDemo/Controllers/FloatingPictureViewController.swift",
    "chars": 2263,
    "preview": "//\n//  FloatingPictureViewController.swift\n//  MultipeerDemo\n//\n//  Created by Guilherme Rambo on 24/03/18.\n//  Copyrigh"
  },
  {
    "path": "MultipeerDemo/Controllers/LoadingOverlayViewController.swift",
    "chars": 2473,
    "preview": "//\n//  LoadingOverlayViewController.swift\n//  MultipeerDemo\n//\n//  Created by Guilherme Rambo on 23/03/18.\n//  Copyright"
  },
  {
    "path": "MultipeerDemo/Controllers/UIImage+Orientation.swift",
    "chars": 643,
    "preview": "//\n//  UIImage+Orientation.swift\n//  MultipeerDemo\n//\n//  Created by Guilherme Rambo on 24/03/18.\n//  Copyright © 2018 G"
  },
  {
    "path": "MultipeerDemo/Controllers/UIViewController+Children.swift",
    "chars": 510,
    "preview": "//\n//  UIViewController+Children.swift\n//  MultipeerDemo\n//\n//  Created by Guilherme Rambo on 23/03/18.\n//  Copyright © "
  },
  {
    "path": "MultipeerDemo/Core/PeerService.swift",
    "chars": 5747,
    "preview": "//\n//  PeerService.swift\n//  MultipeerDemo\n//\n//  Created by Guilherme Rambo on 23/03/18.\n//  Copyright © 2018 Guilherme"
  },
  {
    "path": "MultipeerDemo/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json",
    "chars": 1495,
    "preview": "{\n  \"images\" : [\n    {\n      \"idiom\" : \"iphone\",\n      \"size\" : \"20x20\",\n      \"scale\" : \"2x\"\n    },\n    {\n      \"idiom\""
  },
  {
    "path": "MultipeerDemo/Resources/Base.lproj/LaunchScreen.storyboard",
    "chars": 1750,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<document type=\"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB\" version=\"3"
  },
  {
    "path": "MultipeerDemo/Resources/Info.plist",
    "chars": 1464,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/P"
  },
  {
    "path": "MultipeerDemo/Views/CSBigRoundedButton.swift",
    "chars": 5405,
    "preview": "//\n//  CSBigRoundedButton.swift\n//  CutenessKit\n//\n//  Created by Guilherme Rambo on 22/02/18.\n//  Copyright © 2018 Guil"
  },
  {
    "path": "MultipeerDemo.xcodeproj/project.pbxproj",
    "chars": 16350,
    "preview": "// !$*UTF8*$!\n{\n\tarchiveVersion = 1;\n\tclasses = {\n\t};\n\tobjectVersion = 48;\n\tobjects = {\n\n/* Begin PBXBuildFile section *"
  },
  {
    "path": "MultipeerDemo.xcodeproj/xcshareddata/xcschemes/MultipeerDemo.xcscheme",
    "chars": 3565,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Scheme\n   LastUpgradeVersion = \"1030\"\n   version = \"1.3\">\n   <BuildAction\n      "
  },
  {
    "path": "README.md",
    "chars": 470,
    "preview": "# MultipeerDemo\n\nA sample app showing how to transfer files between two devices using [MultipeerConnectivity](https://de"
  }
]

About this extraction

This page contains the full source code of the insidegui/MultipeerDemo GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 17 files (55.5 KB), approximately 15.3k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!