I am trying to access a Swift Extension to NSString from an objective-C class using the @objc prefix but can't access an optional.
Now that Swift 4.2 requires @objc before variables or functions called from Objective-C, to access the extension, I…
I've just learned about extensions and I was wondering, there was an example about extending a protocol. For example, let's say we have the protocol:
protocol CanFly {
func canFly()
}
which allows all the classes who can fly to basiclly to fly.…
I am trying to make a Swift extension for NSArray that uses some Swift methods but am having trouble with the firsts step of creating a properly formatted Swift Array from the NSArray.
The incoming NSArray looks like…
My goal is to have a function available through all Sequence like Array or Set.
This function should return a Bool telling whether there is at least one object present in both sequences or not.
// Usage
let s1 = ["hi", "hey", "ho"]
let s2:Set =…
When I try to create a UIImage extension in Swift 5, like this:
extension UIImage {
}
I get this error:
'UIImage' is ambiguous for type lookup in this context
What causes this and how do I avert it?
Thanks!
I am using following code to encode my string url
let originalString = "test/test"
let escapedString = originalString.addingPercentEncoding(withAllowedCharacters: . urlQueryAllowed)
print(escapedString!)
I am looking for Swift extension to encode…
So I have a UIButton Extension that allows all the buttons in my app to have a nice subtle animation. But recently I have thought of giving a few buttons a special animation but I am not sure how to give those few buttons a specific different…
I have a Swift project in which I use 2 extensions on any Collection type. They allow for safe access to elements in an array. Here's the extensions:
subscript (safe index: Index) -> Element? {
return indices.contains(index) ? self[index] :…
From the Apple documentation, UIDatePicker.Mode is an enum of type Int with four cases.
enum Mode : Int
case time
case date
case dateAndTime
case countDownTimer
I am curious to know whether I can add a fifth case monthYear (= 4) to enable me to…
I have a DataManager class and it has some relevant functions and variables. For example,
Class DataManager: NSObject {
func doSomething()
func doSomethingAgain()
}
I move few method to an extension of DataManager. I made the extension as…
Background
I am creating an extension for UITableViewController like so:
func attachToController(_ sender: C, alignTo: UIView, to: ALEdge = .top , withOffset: CGFloat = 0.0)
where C: UITableViewDataSource,…
I need ability to send email in a number of view controllers in my app. The code is same, take three params -- recipient address, body, and subject. If Mail is configured on device, initialize MFMailComposeViewController with the view controller as…
I have places where I have both Set and Array of MyType.
In these places, I need to filter down my Sequences, and you'll notice that the filter block is the same for both Sequence types.
Is there any way I can implement a generic Sequence extension,…
I've created a 'configure' infix operator '=>' which lets me configure objects inline, allowing me to both define and initialize properties and/or call methods/functions at the assignment level.
For instance, instead of this, which requires an…
I am creating night mode using Swift 4.2(Notification Center
). I followed https://medium.com/@mczachurski/ios-dark-theme-9a12724c112d this tutorial and able change the colour for only labels. check the below list what all things need to change…