swift – AlbeBaubles https://albebaubles.com Mobile & IoT Development Wed, 03 Jul 2024 01:08:57 +0000 en hourly 1 https://wordpress.org/?v=6.8.1 https://albebaubles.com/wp-content/uploads/2019/10/cropped-247306-3-32x32.png swift – AlbeBaubles https://albebaubles.com 32 32 Proposal: Swift Extension Naming Convention https://albebaubles.com/swift/proposal-swift-extension-naming-convention/ https://albebaubles.com/swift/proposal-swift-extension-naming-convention/#respond Wed, 03 Jul 2024 00:58:47 +0000 https://albebaubles.com/?p=1011 Continue reading Proposal: Swift Extension Naming Convention]]> Proposal: Standardizing Naming Conventions for Extension Files

Introduction

As a consultant with extensive experience in software development, I have observed a wide range of naming methodologies employed across various projects and organizations. One area that often lacks standardization is the naming convention for extension files. The inconsistency in naming conventions can lead to confusion, reduced code readability, and increased maintenance overhead.

Proposal

To address this issue, I propose adopting a standardized naming convention for extension files: (classname).Extension.

Justification

1. Clarity
Naming the extension file as “(classname).Extension” provides immediate clarity about the file’s purpose. It clearly indicates that the file contains extensions for a specific class or structure, reducing ambiguity and helping developers quickly understand the file’s role without needing to delve into its contents.

2. Organization
This naming convention aids in organizing files within a project. When files are named consistently, it becomes easier to locate and manage them. For instance, if you have a class named Customer, the Customer.Extension file will be instantly recognizable as containing extensions related to the Customer class.

3. Consistency
Applying a standard naming convention across the project or organization ensures consistency. This is particularly beneficial in larger teams or projects where multiple developers are working on the same codebase. Consistent naming conventions reduce cognitive load and streamline onboarding for new team members.

4. Searchability
Using a consistent naming pattern makes it easier to search for related files. If you need to find all extensions, you can simply search for “.Extension” within your codebase.

5. Documentation and Communication
A standard naming convention facilitates clear and concise communication in meetings and documentation. For example, instructing a colleague to “check the Order.Extension file” immediately conveys where to look.

Implementation Example

Consider a project with the following classes and structures:

Customer.cs
Order.cs
Product.cs

Using the proposed naming convention, the corresponding extension files would be:

Customer.Extension.cs
Order.Extension.cs
Product.Extension.cs

This approach makes it evident that each extension file is related to its respective class, thereby enhancing code organization and developer efficiency.

Implementation Plan

1. Team Adoption
Ensure that all team members are aware of and adhere to this naming convention. Conduct a workshop or meeting to discuss the benefits and implementation of the new convention.

2. Update Existing Files
If the project is already in progress, consider renaming existing extension files to match the new convention. This can be done incrementally to avoid disrupting ongoing development.

3. Integrate into Guidelines
Include this naming convention in your project’s coding guidelines or style guide. This ensures that new code adheres to the standard and helps maintain consistency over time.

4. Automated Enforcement
Consider using code analysis tools or scripts to enforce the naming convention. These tools can automatically check file names and alert developers to any deviations from the standard.

Conclusion

Adopting the proposed naming convention for extension files—(classname).Extension—will improve the clarity, organization, and consistency of your codebase. This standardization will enhance developer efficiency, streamline communication, and make it easier to maintain and scale your projects. I encourage you to consider implementing this convention and look forward to discussing its potential benefits further.

UntitledImage

]]>
https://albebaubles.com/swift/proposal-swift-extension-naming-convention/feed/ 0
Finding unused Swift variables https://albebaubles.com/swift/finding-unused-swift-variables/ https://albebaubles.com/swift/finding-unused-swift-variables/#respond Tue, 02 Apr 2024 17:33:56 +0000 https://albebaubles.com/?p=948 Nifty little script (from Paul Taykalo) to find unused variables in swift code.

PaulTaykalo/swift-scripts:

UntitledImage

]]>
https://albebaubles.com/swift/finding-unused-swift-variables/feed/ 0
Milracks – AlbeBaubles https://albebaubles.com/swift/milracks-albebaubles/ https://albebaubles.com/swift/milracks-albebaubles/#respond Sat, 24 Feb 2024 14:38:48 +0000 https://albebaubles.com/?p=930 Check out our newest app on the App Store! 100% SwiftUI.

Milracks – AlbeBaubles:

]]>
https://albebaubles.com/swift/milracks-albebaubles/feed/ 0
Too easy https://albebaubles.com/swift/too-easy/ https://albebaubles.com/swift/too-easy/#respond Sat, 19 Feb 2022 04:10:07 +0000 https://albebaubles.com/?p=554 A great example of how simple it is to construct a user interface in swiftUI

UntitledImage UntitledImage

]]>
https://albebaubles.com/swift/too-easy/feed/ 0
Extending UIColor https://albebaubles.com/swift/extending-uicolor/ https://albebaubles.com/swift/extending-uicolor/#respond Thu, 10 Feb 2022 01:13:04 +0000 https://albebaubles.com/?p=497 I use this so often I’ve added it to my global utilities class.  Seriously considering taking all my extensions open source – since I use in my utilities class at all clients.

extension UIColor {
    public func uiImage(_ size: CGSize = CGSize(width: 0.1, height: 0.1)) -> UIImage {
        UIGraphicsImageRenderer(size: size).image { rendererContext in
            self.setFill()
            rendererContext.fill(CGRect(origin: .zero, size: size))
        }
    }

	 /// creates a cgImage from this color
	 /// - Parameter size: (CGSize) the size of the image
	 /// - Returns: cgImage
  public func cgImage(_ size: CGSize = CGSize(width: 0.1, height: 0.1)) -> CGImage {
        self.uiImage(size).cgImage!
    }

	 /// creates a square Swift Image with this color as background
	 /// - Parameters:
	 ///   - size: size of the image to be created
	 ///   - label: text to dispaly within the image
	 /// - Returns: cgImage
    public func swiftImage(_ size: CGSize = CGSize(width: 0.1, height: 0.1),
                           _ label: String = String.empty) -> Image {
        Image(self.cgImage(size), scale: CGFloat(2), label: Text(verbatim: label))
    }


	 /// creates a Swift Color from this UIColor
	 /// - Returns: Swift Color
  public func swiftColor() -> Color {
	 Color(self)
  }
}

 

]]>
https://albebaubles.com/swift/extending-uicolor/feed/ 0
Ad block – AlbeBlocksAnnoyances https://albebaubles.com/swift/ad-block-albeblocksannoyances/ https://albebaubles.com/swift/ad-block-albeblocksannoyances/#respond Sun, 12 Jan 2020 16:56:02 +0000 http://albebaubles.com/?p=109 Continue reading Ad block – AlbeBlocksAnnoyances]]> [UPDATED TO SUPPORT iOS]

I quit using Facebook well over a year ago, yet anytime my browser takes me there it shows me logged in.  I DO connect to FB on my oculus – no choice.  I don’t know how, but it sure seems using the oculus somehow communicates with my Mac and logs me into FB.

I took matters into my own hands, and wrote a quick Safari extension that blocks all things Facebook, as well as 3500 or more ad sites.

The app is open source and available at:

 

https://github.com/albebaubles/AlbeBlocksAnnoyances

 

 

NewImage

]]>
https://albebaubles.com/swift/ad-block-albeblocksannoyances/feed/ 0
Fold code for functions you don’t mutate https://albebaubles.com/opinion/collapse-code-for-functions-you-dont-mutate/ https://albebaubles.com/opinion/collapse-code-for-functions-you-dont-mutate/#respond Sun, 05 Jan 2020 22:24:11 +0000 http://albebaubles.com/?p=90 Continue reading Fold code for functions you don’t mutate]]> Something I’ve found very helpful for my busy mind is to fold the code within functions I’ll rarely mutate. Folding/Unfolding code is as easy as tapping option-command-leftarrow to fold and option-command-rightarrow to unfold.

So take the following code:

NewImage

Place the cursor anywhere within the function brackets and tap option-command-leftarrow, and this is what you have:

NewImage

One heck of a lot cleaner, and easy to unfold by either clicking the ellipsis or tapping option-command-rightarrow. Encourage your developers to use this practice – once comfortable with it, you’ll save time.

Of course — do not forget the code folding options from the editor menu to be able to fold or unfold entire files.

]]>
https://albebaubles.com/opinion/collapse-code-for-functions-you-dont-mutate/feed/ 0
SwiftUI – NSAttributedString https://albebaubles.com/swift/swiftui-nsattributedstring/ https://albebaubles.com/swift/swiftui-nsattributedstring/#respond Sun, 20 Oct 2019 05:18:59 +0000 http://10.0.1.200/wordpress/?p=33 While it’s true SwiftUI doesn’t currently provide easy access to NSAttributedString, you can concatenate string literals assigning attributes to each literal individually:

Text("Regular, ") + 
Text("Italic, ").italic() + 
Text("Bold, ").bold() + 
Text("Blue").foreground(.blue)

Not pretty, but it works

]]>
https://albebaubles.com/swift/swiftui-nsattributedstring/feed/ 0
ABControls updated for swift 5. https://albebaubles.com/pods/abcontrols-updated-for-swift-5/ https://albebaubles.com/pods/abcontrols-updated-for-swift-5/#respond Tue, 09 Jul 2019 05:14:07 +0000 http://10.0.1.200/wordpress/?p=31 https://github.com/albebaubles/ABControls

]]>
https://albebaubles.com/pods/abcontrols-updated-for-swift-5/feed/ 0
ABControls https://albebaubles.com/pods/abcontrols/ https://albebaubles.com/pods/abcontrols/#respond Sun, 14 Oct 2018 05:07:15 +0000 http://10.0.1.200/wordpress/?p=26 I wanted to learn more about @IBDesignable and @IBInspectable, so I thought why not throw together a quick Custom UI Control project – contains such things as dropdown boxes, list boxes, barcode scanner, creater.

https://github.com/albebaubles/ABControls

]]>
https://albebaubles.com/pods/abcontrols/feed/ 0