I have a core data generated class called Message. Message has a message property that for some reason is inaccessible in Swift.
You can clearly see the message property here in the header file
In a Swift extension of Message I'm unable to access…
I am relatively new to iOS and would appreciate any help figuring out how to create an array of images when using an extension to help manage downloads and caching. I've been going around in circles with this for a couple hours so thought it was…
extension Array where Element: StringLiteralConvertible{
func spliteByPrefix() -> [Element]{
for item in self{
}
return []
}
}
I want to write an extension of Array whose Element is always a String. And in my…
I have UIImageView extension that is downloading image from given url in background. I'm using it to fetch images for UITableViewCell. After successful download I'm calling self.setNeedsLayout() but it does not refresh layout of cell since this…
I am trying to convert the current values that I am dealing with to hundredths. Here is my code:
extension String {
var value: Int {
if let found = Array("abc".characters).indexOf(Character(lowercaseString)) {
return found +…
When working with Swift - Extensions
As you know, we can create variables for function. i want to create a variable which can hold reference to a function which has parameters.
i have managed to create variable for a function which didn't have any…
The Alamofire API has extensions such as extension Request in ResponseSerialization.swift. When designing a Swift API why would you take this approach as opposed to just adding these methods to the Request class (Request.swift)?
I understand the…
This is working great for Doubles and Floats. But getting other numerals like Ints involved is proving really difficult.
public protocol TemperatureConvertable: FloatLiteralConvertible, CustomStringConvertible {
func +(lhs: Self, rhs: Self) ->…
I'm new to Swift and is trying to learn the concept of extension. I saw this code in "the swift programming language", which tries to return the decimal digit 'n' places in from the right of the number. The code work fine, but I am struggling to…
The below code does not compile for me:
import Foundation
@objc public protocol MyProtocol {
func protocolMethod(parameter: (String)) -> String
func anotherProtocolMethod() -> Int
}
class MyClass: NSObject {
var myValue =…
class X: Interface1, Delegate1, Delegate2 {
var sharedVariable = true
.... very long code comes here, that implements the delegates ...
}
How can I now break down this long class? I was thinking of using extensions, something like
extension…
I want to rewrite the description property in NSDictionary by textension in swift, but can't figure how. This is very easy and common in Objective-C by using category, I can just do as this:
@implementation NSDictionary (Log)
- (NSString…
I created extension for UITextField. And I need the same extension for UITextView. How to make this extension available for all other views?
My extension code:
extension UITextField {
func addTopBorderWithColor(color: UIColor, height: CGFloat)…
I have some swift structs for which protocol compliance is generated with individual extensions with equal methods names which just differ in their return types which are struct dependent. On top of That I want to use them in a generic function…
I have tried to get a UICollectionview into my keyboard extension, which i made in swift. But i can´t get it to work. The keyboard just crashes on launch. Anyone know how to fix this? Or is it even possible to use a UICollectionview in a keyboard…