Replacing Multiple Occurrences in Array
Swift 4.1, Xcode 9.3
I want to make an extension alike an extension I made for Array for String.
String Extension:
public extension String {
///
/// Replaces multiple occurences of…
I want to move custom colors to an extension of UIColor:
extension UIColor {
static var nonSelectedTabColor: UIColor {
return UIColor(white: 0.682, alpha: 1) // #AEAEAE
}
}
But on trying to access it, its causing me an…
I want to implement a theming in a way, that a feature can add its needed colors to a Theme protocol, so that any actual theme implementation must provide colors for every feature. I also want to have the theme implementation and feature theme…
I have some custom colors for my application and now its saves like a dictionary, but I think this is no really good idea and I want to do extension for UIColor with a custom color.
That may look like this
var newColor = UIColor.MyColor // like…
I like how Swift lets you define a method in a protocol, then via an extension of that protocol, implement that method. However, specifically for cases where you're defining the protocol and the extension in the same scope and with the same access…
I have a question in swift extension:
protocol Racer {
var speed: Double { get }
}
extension Sequence where Iterator.Element == Racer {
func fastest() -> Iterator.Element? {
return self.max(by: { (a: Iterator.Element, b:…
I have custom colors within my code. I use them several times and I would like to have them allocated only once.
The situation / problem
If we get a look at UIColor headers we can see the following :
[...]
// Some convenience methods to create…
I want to create a single extension for both UITextField and UITextView and add a below method to it:
func addDoneButtonOnKeyboardWith(selector : Selector)
{
let keyBoardToolBar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 320,…
Assume I'm writing a social media crawler that handle's multiple accounts (e.g. Facebook, Twitter, etc.)
I define a few protocols for messages (Message has display-name and message body, Timestamped has a timestamp, Forwarded has the original…
For rotating an UIImage I used an extension which is downloaded from the internet. There, rotating is working but there are some wired behaviours.
This is the extension code
import UIKit
extension UIImage {
public func…
I'm trying to create an extension for my FieldIdentifiable protocol only where the enum that implements it has a RawValue of Int. The only problem is that the return FieldIdItem(rawValue: newValue) line keeps showing this error:
'Self.FieldIdItem'…
I've read that global variables are bad. But, what about global functions? Say I add to my iPhone app project a file called Globals.swift containing func foo() { print("foo") }. Isn't that bad because it could conflict with other global functions of…
(This probably needs a better title...)
I would like to have a set of accessors I can use in code to quickly express time durations. E.g:
42.seconds
3.14.minutes
0.5.hours
13.days
This post illustrates that you can't just do it with a simple new…
It seems that it's a bug and resolved in Xcode 7 with Swift(2b3)
To make convenient observation, let's post the code to playground, the result will be indicated by the comments.
extension Int {
var sq: Int {
mutating get {
…
I am using @IBInspectable to set a border color on a UIButton using a Swift extension like this:
extension UIButton {
@IBInspectable var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set {
layer.borderWidth =…