BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: Day 11 Extensions

Forums > 100 Days of SwiftUI

extension String {
    var isLong: Bool {
        return count > 25
    }
}

shouldn't this be wrong

thats right :

extension String {
    var isLong: Bool {
        return self.count > 25
    }
}

don't we have to use self

1      

You don't necessarily need to use self within an extension when referring to properties of the thing being extended. It only becomes necessary if the compiler needs additional information. It doesn't hurt anything to use it, though, so if it makes more sense to you to do so, then by all means do.

1      

Howdy,

Another thing to keep in mind is 99.6% of what you learn from Paul is accurate, however some of these videos were made back when XCode 9.3 was being used. The information is almost entirely correct...excpet .self which received a major update with XCode 12.

There is nothing wrong with using .self, however XCode was improved & many times we do not need to use .self anymore.

1      

Hacking with Swift is sponsored by Guardsquare

SPONSORED AppSweep by Guardsquare helps developers automate the mobile app security testing process with fast, free scans. By using AppSweep’s actionable recommendations, developers can improve the security posture of their apps in accordance with security standards like OWASP.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.