Skip to content

Instantly share code, notes, and snippets.

View nathanborror's full-sized avatar

Nathan Borror nathanborror

View GitHub Profile

Using Swift Package Manager with iOS

Step 1:

File > New > Project...

Step 2:

Create a Package.swift file in your root project directory, add dependencies, then run swift package fetch on the command line in the same directory. We’re not going to run swift build because it will just complain.

//
// PagerController.swift
//
import UIKit
open class PagerController: BaseViewController {
let scrollView = UIScrollView()
let viewControllers: [UIViewController]
// Table Cells
protocol TableCell {
associatedtype A: Any
associatedtype Cell: UITableViewCell
static func cell(for items: [A], at indexPath: IndexPath, of tableView: UITableView, configure: (cell: Cell, item: A) -> Void) -> Cell
}
extension NSMutableAttributedString {
func add(attribute: Attribute, range: NSRange) throws {
guard (range.location + range.length) <= length else {
throw AttributedStringError.InvalidRange(range: range)
}
addAttribute(attribute.name, value: attribute.value, range: range)
}
}

tshark

Capturing traffic

Capture some traffic and save in ‘pcap’ format:

$ tshark -w capture.pcap

Reading captured data

// Markup (based on Draft.js: http://facebook.github.io/draft-js)
package draft
import (
"encoding/json"
"fmt"
)
type Markup struct {
Blocks []Block `json:"blocks"`
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let builder = HelloRequest.Builder()
builder.name = "Bob"
do {
let req = try builder.build()
defmodule Nthn.Entry.Handler do
import Ecto.Query
alias Nthn.Entry
alias Nthn.Repo
def init({:tcp, :http}, req, opts) do
{:ok, req, opts}
end
def handle(req, state) do
struct Item {
let title: String
}
// Resources
let itemResource = Resource<Item> { callback in
let items = [Item(title: "Foo"), Item(title: "Bar"), Item(title: "Baz")]
callback(items)
}

iOS Over the Air App Distribution

  • Export your app using Xcode's Organizer, be sure and choose Save for Ad Hoc Deployment
  • Create a folder on Dropbox and add your app's .ipa file
  • Add app.plist to your folder with the following contents:
<?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">