I'm trying to override the debugDescription property when displaying the value of NSDate objects in the Xcode debugger.
My extension code:
import Foundation
extension NSDate {
public override var debugDescription: String {
return…
I've created simple extension for Array which will append only unique elements. It works fine until I want to work with an array of optionals. Since that I'm keep getting error
Type 'Event?' does not conform to protocol 'Equatable'
Event…
My code is written in Swift 2.0 and with a deployment target of iOS 8.0 or later. I am trying to extend UIView so that instead of using UIView.animateWithDuration(), I can use my custom function. I want to take a UIView that's a circle and keep it…
(feel free to retitle question as appropriate)
I'm working with a lot of BLE data, and for debugging purposes, I've found it easy to extend UInt8 with a HEX computed variable:
extension UInt8 {
var HEX:String {
return String(format:…
I'm struggling to understand protocols and protocol extensions in swift.
I'm wanting to define a series of protocols that can be applied to a class, along with a set of protocol extensions to provide default implementations. Example code:
// MARK:…
i'm trying to create an extension for the Array struct in order to add methods just if the contained objects conforms to a particular protocol, but i'm having strange behaviors when i try to access to a method in the extension from a class.
here is…
I've written some code that I think ought to work in Swift 2 (Xcode 7b4), but it's not compiling. I'm hoping to get some thoughts on whether what I'm trying to do should be valid.
Consider this example Array extension:
extension Array where…
I upgraded XCode to 6.3 / Swift 1.2 and I'm seeing errors with extensions. Below is my extension to UINavigationItem for hiding the backButton text.
extension UINavigationItem {
func backBarButtonItem() -> UIBarButtonItem {
return…
Been having lots and lots of trouble with Swift protocols in combination with arrays, but I couldn't even reproduce my whole problem before things started to break in playground. Here's a minimal example.
I have two protocols and a class Bus which…
I'm new to generics in swift, and while reading some books, I came across something I don't understand. In generic functions, when is it appropriate to use the type parameter (the right after the function name)? and when is it inappropriate?
Here…
Is there any existing function that looks for the index of a substring inside another string? A method like .indexOfSubstring thank does this:
let word: String = "Hey there, how are you?"
let indexOf: Int = word.indexOfSubstring("ere, how…
I made this extension to NSView to make it easier to work with views.
import Cocoa
public extension NSView {
var invertedFrame: NSRect {
get {
return NSRect(x: frame.origin.x,
y: superview.bounds.height -…
I created an extension for the UIView:
import UIKit
extension UIView {
var frameHeight : CGFloat {
get {
return self.frame.size.height
}
set(newHeight) {
self.frame =…
How to assign updated value to Text value in Extension SwiftUIenter image description here
extension Text {
public func translate(text: String) -> Text{
var translated = ""
let conditions =…
I am trying to add a protocol which has all the attributes and functions of a Process but I see a warning with terminationHandler.
I was hoping not to see this warning since @Sendable is already added to terminationHandler.
protocol ProcessProtocol…