Protocols
The following protocols are available globally.
-
This was taken straight from the objc.io book “Advanced Swift.” It’s so damn useful, that I have it made into a standard tool.
The original design was done by Ole Begemann and Chris Eidhof. I have modified it slightly; but not much.
It is fast as all git-go.
A type that can efficiently “enqueue” and “dequeue” elements. It works on one element at a time. You cannot dequeue groups of elements.
See moreDeclaration
Swift
public protocol OLEB_Queue
-
If you conform to this protocol, you get a few basic Sequence attributes for free.
You’ll need to set up a sequence_contents Array (read/write), and set the Element type, and that’s about all.
This also gives you a read-only subscript.
This cannot be applied to enums, as it requires a stored property.
See moreDeclaration
Swift
public protocol RVS_SequenceProtocol : Sequence -
This protocol is an abstract base for IP addresses. When we parse a String as an IP address, it will return a specific implementation of this.
When we say “valid,” we don’t mean the address resolves to anything; just that it is syntactically correct.
Its principal use is to take a string that was generated by something like a text entry, and establish a proper IP address from that string. It’s a smart parser.
What Problem Does This Solve?
This was designed to allow us to simply represent IP addresses properly. This was mainly due to the complex nature of IPv6 addressing; with its “shortcut” syntax, representing contiguous runs of zeroes.
This class reads these, and will also give you properly formatted (and shortened) strings.
Usage
Start With A String
The struct can be instantiated by supplying a String, with a valid representation of either an IPv4 IP address, or an IPv6 IP address.
The struct will parse the String, and will store an internal Array of Ints, representing that IP address.
It will then be able to return the IP address in whatever format is required.
It validates the correctness of the address before storing it, so you know that the address is always in a valid form.
It does not verify that the address actually leads anywhere. It merely ensures that it is a correctly-formed IP address.
You can submit any string, and the factory method will ensure that an instance of the correct IP version handler is generated.
Example
if let testIP = RVS_IPAddressExtractIPAddress("1.2.3.4") { print("This should be an IPv4 Address: \(String(describing: testIP))") } if let testIP = RVS_IPAddressExtractIPAddress("1:2:3:4:5:6:7:8") { print("This should be an IPv6 Address: \(String(describing: testIP))") }You can also add TCP ports to the address:
if let testIP = RVS_IPAddressExtractIPAddress("1.2.3.4:5") { print("This should be an IPv4 Address: \(String(describing: testIP))") } if let testIP = RVS_IPAddressExtractIPAddress("[1:2:3:4:5:6:7:8]:9") { print("This should be an IPv6 Address: \(String(describing: testIP))") }The resulting addresses can be accessed as Arrays of Int, or as String, either with or without the TCP port.
See moreDeclaration
Swift
public protocol RVS_IPAddress
View on GitHub
Protocols Reference