A collection of Swift functions, extensions, and SwiftUI and UIKit Views.

Overview

J's Helper

A collection of Swift functions, extensions, and SwiftUI and UIKit Views.

Legend:

  • ๐Ÿ”ธ UIKit
  • ๐Ÿ”น SwiftUI
  • ๐Ÿ”บ Shared

Installation

  1. In XCode 12 go to File -> Swift Packages -> Add Package Dependency or in XCode 13 File -> Add Packages
  2. Paste in the repo's url:
https://github.com/JemAlvarez/JsHelper

Import

JsHelper

import JsHelper

Onboarder

import Onboarder

UIKit

๐Ÿ”ธ Add constraints on all anchors for a view

yourSubview.addConstraints(equalTo: yourParentView)

๐Ÿ”ธ Setup UIKit with no Storyboards

  1. Add the following code in SceneDelegate
  2. Follow steps in makeWindow function documnetation
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
	if let window = makeWindow(for: scene, with: ViewController()) {
		self.window = window
	}
}

๐Ÿ”ธ Get hex string from UIColor

UIColor.blue.getHexString()

๐Ÿ”ธ Initialize UIColor from hex string

UIColor(hex: "#000000")

๐Ÿ”ธ PropertyWrapper for translatesAutoresizingMaskIntoConstraints

// From 
var view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
// To
@TAMIC var view = UIView()

SwiftUI

๐Ÿ”น Get hex string from Color

Color.blue.getHexString()

๐Ÿ”น Initialize Color from hex string

Color(hex: "#000000")

๐Ÿ”น Get current UIWindow

if let window = UIApplication.shared.currentUIWindow() {
	// handle ui window
}

๐Ÿ”น Present Share Sheet

Button("Present Sheet") {
	presentShareSheet(with: ["Strings", Images, URLs])
}

๐Ÿ”น Request AppStore Review

Button("Request Review") {
	requestReview()
}

๐Ÿ”น Open Link

@Environment(\.openURL) var openURL

Button("Open Link") {
	// Takes in an `OpenURLAction` doesn't have to be `openURL`
	openLink("https://apple.com", with: openURL)
}

๐Ÿ”น Give view radius on custom corners

yourView
	.cornerRadius(50, corners: [.bottomLeft, .topRight])

๐Ÿ”น Get View size (width & height)

yourView
	.getViewSize { width, height in
		// Now you can add your width and height to your state and use it
	}

๐Ÿ”น Haptic feedback

Button("Haptic") {
	// Default HapticStyle is `soft`
	haptic()
	// Other HapticStyles: light, medium, heavy, rigid, soft, success, error, warning, selection
	haptic(.heavy)
}

๐Ÿ”น Guage Progress View

ProgressView("Progress", value: 69, total: 420)
	.progressViewStyle(
		GaugeProgressViewStyle(
			strokeColor: .red, 
			strokeWidth: 15, 
			size: (50, 50)
			// backgroundColor: Color? = nil
		)
	)

๐Ÿ”น Alert bubble view (localizable)

@State var showing = false
    
var body: some View {
	ZStack {
		// iOS 14 - Color for background 
		AlertBubbleView14(
			showing: $showing, 
			title: "Title", 
			subtitle: "Subtitle", 
			systemImage: "heart.fill", 
			background: .red
		)

		// iOS 15 - ShapeStyle for background
		AlertBubbleView(
			showing: $showing, 
			title: "Title", 
			subtitle: "Subtitle", 
			systemImage: "heart.fill", 
			background: .ultraThinMaterial
		)
	}
}

๐Ÿ”น Fully native emoji picker

@State var emoji = "๐ŸŽ"
    
var body: some View {
	EmojiPickerView(emoji: $emoji)
}

๐Ÿ”น ImagePicker

// UIImage picked from user
@State var image: UIImage? = nil
// Presenting Image Picker
@State var showingPicker = false

var body: some View {
	VStack{
		// unwrap image and display
		if let image = image {
			Image(uiImage: image)
				.resizable()
		}
            
		// show image picker
		Button("Pick photo") {
			showingPicker.toggle()
		}
	}
	// image picker sheet
	.sheet(isPresented: $showingPicker) {
		ImagePickerView(image: $image)
	}
}

Shared

๐Ÿ”บ Date to string with format

// Preset formats
Date().getString(with: .commaWithWeekday)
// Or custom formats
Date().getString(with: "MMMM yyyy")

๐Ÿ”บ Number of day to another date

Date().numberOfDays(until: anotherDate)

๐Ÿ”บ String to Date

"your date in string".toDate(with: "MM/dd/yyyy")
// Or use the Date.Formats
"your date in string".toDate(with: Date.Formats.slashes.rawValue)

๐Ÿ”บ Check if string contains emoji

"emoji ๐Ÿ˜„".hasEmoji()

๐Ÿ”บ Print Error

error.printError(for: "Your label")
// Output
// Error occurred: Your label
// Localized error description
// Full error

๐Ÿ”บ StoreKit localized price string

// iOS 15 Product
yourProduct.localizedPrice ?? "optional string"
// SKProduct
yourSKProduct.localizedPrice ?? "optional string"

๐Ÿ”บ Reset userdefults

UserDefaults.standard.reset(for: ["key1", "key2"])

๐Ÿ”บ Load local JSON Data

let data = Bundle.main.loadLocalJSON(with: "fileName")

๐Ÿ”บ Request User notifications

UNUserNotificationCenter.requestPermission(for: [.alert, .badge, .sound]) {
	// Handle success
}

๐Ÿ”บ Bring back user notification

.onAppear {
	// Triggers a notification 14 (your amount of days) days from the last time the user opened the app
	// With your given notification content
	UNUserNotificationCenter.bringBackUser(with: notificationContent, in: 14)
}

๐Ÿ”บ Fetch data from URL

// iOS 15
let urlData: Data? = await URL(string: "yourURLEndpoint")!.requestData()
// Pre-iOS 15
let urlData: Data? = URL(string: "yourURLEndpoint")!.requestData { data in
    // Use your data
}

๐Ÿ”บ Fetch data from URL and Decode

// iOS 15
let DecodedURLData: YourType? = await URL(string: "yourURLEndpoint")!.requestDataAndDecode()
// Pre-iOS 15
URL(string: "yourURLEndpoint")!.requestDataAndDecode { (data: YourType) in
    // Use your data
}

Onboarder

For detailed usage information on Onboarder, checkout the the Onboarder repo here.

Defaults

Default values for the following:

Font Sizes - Includes all predefined fonts in their CGFloat size

.font(.system(size: .body))

Opacities - Low, Medium, High

.opacity(.opacityLow)

URL - Default unwrapped url

URL(string: "Invalid URL") ?? .defaultURL

Date - Current values (day, month, year, hour, min, etc.)

Date.currentYear

Docs

  • SwiftLint.md file has steps on how to setup SwiftLint, usage, and a config file. For more information check here.
  • Fonts.md file has a table of the predefined font sizes
  • GitIgnore.md file includes a files to ignore in XCode projects
  • NavigationControllerPopGesture shows hot to bring back pop gesture after hiding navigation back button

Meta

Jem Alvarez โ€“ @official_JemAl โ€“ [email protected]

Distributed under the MIT license. See LICENSE for more information.

JsHelper

You might also like...
Introspect underlying UIKit components from SwiftUI
Introspect underlying UIKit components from SwiftUI

Introspect for SwiftUI Introspect allows you to get the underlying UIKit or AppKit element of a SwiftUI view. For instance, with Introspect you can ac

A collection of missing SwiftUI components
A collection of missing SwiftUI components

SwiftUIKit A collection of components that will simplify and accelerate your iOS development. Components CurrencyTextField AdaptToKeyboard (not needed

Native iOS app built in SwiftUI, displays a collection of user's books.

Native iOS app built in SwiftUI, displays a collection of user's books.

Animated shine effect for your views
Animated shine effect for your views

Shine-View-SwiftUI Animated shine effect for your views @State var animateTrigger = false var body: some View { Button(action: { animate

Adventures-with-Swift - Building Native iOS Apps with UIKit and SiwftUI  ๏ฃฟ
Adventures-with-Swift - Building Native iOS Apps with UIKit and SiwftUI ๏ฃฟ

Adventures with Swift, UIKit, & SwiftUI As I have experience working with React Native and have dabbled a bit with Flutter, I've decided to dive in th

Restaurant App iOs swift Uikit

Restaurant-App Restaurant App iOs swift Uikit if you want to use this app first install CocoPods $ sudo gem install cocopods and then use this comman

๐ŸŽฌ Netflix Clone ๐Ÿ”ฅ Made using UIKit with Swift language.
๐ŸŽฌ Netflix Clone ๐Ÿ”ฅ Made using UIKit with Swift language.

Made using UIKit with Swift language. Core Data was used as the local database. Tmdb and youtube api were used for the API.

Swift UIKit E-Commerce (UgurShopping)  No StoryBoard   Firebase, FireStore, FirebaseAuth, KingFisher, SwiftEntryKit, ProgressHud, Alamofire UICollectionViewCompositionalLayout, NotificationCenter
Swift UIKit E-Commerce (UgurShopping) No StoryBoard Firebase, FireStore, FirebaseAuth, KingFisher, SwiftEntryKit, ProgressHud, Alamofire UICollectionViewCompositionalLayout, NotificationCenter

Swift UIKit E-Commerce (UgurShopping) No StoryBoard Firebase, FireStore, FirebaseAuth, KingFisher, SwiftEntryKit, ProgressHud, Alamofire UICollectionViewCompositionalLayout, NotificationCenter

A collection of additional custom SFSymbols for Swift
A collection of additional custom SFSymbols for Swift

MoreSFSymbols A collection of additional custom SFSymbols for Swift Content Usage Symbols Developer Logos Contributing Licence Usage iOS 15.0: Downloa

Owner
Jem Alvarez
Web Dev | Game Dev | iOS Dev
Jem Alvarez
Swift package adding extensions to SwiftUI.

swiftui-extensions SwiftUIX is an umpteenth package containing extensions for Apple's SwiftUI framework. Content The package currently provides the fo

Alexandre H. Saad 2 Jun 13, 2022
SwiftUI Backports - Introducing a collection of SwiftUI backports to make your iOS development easier

SwiftUI Backports Introducing a collection of SwiftUI backports to make your iOS development easier. Many backports support iOS 13+ but where UIKIt fe

Shaps 530 Dec 28, 2022
Joseph Heck 21 Dec 14, 2022
Simple SwiftUI ViewModifier to easily align your views!

Align Align gives you an easy way to align views in SwiftUI. Simply import Align in whichever SwiftUI view you like and you're good to go. Align suppl

Jacob's Apps 26 Mar 15, 2022
A Figma component preview for your SwiftUI views

FigmaPreviewSwiftUI A Figma component preview for your SwiftUI views. You can use Figma components instead of real views within your app until you imp

Danis Tazetdinov 50 Dec 23, 2022
A realistic reflective shimmer to SwiftUI Views that uses device orientation. Position any View relative to device orientation to appear as if through a window or reflected by the screen.

A 3d rotation effect that uses Core Motion to allow SwiftUI views to appear projected in a specific direction and distance relative to the device in r

Ryan Lintott 235 Dec 30, 2022
A Swift library for documenting, isolating, and testing SwiftUI, UIKIt & AppKit components.

A Swift library for documenting, isolating, and testing SwiftUI, UIKit & AppKit components. Minimal Example An example demonstrated with the Slider ui

Hayden Pennington 9 Dec 15, 2022
content for Using Combine - notes on learning Combine with UIKit and SwiftUI

SwiftUI-Notes A collection of notes, project pieces, playgrounds and ideas on learning and using SwiftUI and Combine. Changes, corrections, and feedba

Joseph Heck 1.7k Dec 27, 2022
Movie Database app made with SwiftUI and UIKit

HW4_DogukaanKilicarslan Movie Data Base App made with SwiftUI Movie Database app made with SwiftUI Preview Movie Data Base App : Star Wars Characters

null 1 Oct 20, 2021
Porting the example app from our Advanced iOS App Architecture book from UIKit to SwiftUI.

SwiftUI example app: Koober We're porting the example app from our Advanced iOS App Architecture book from UIKit to SwiftUI and we are sharing the cod

raywenderlich 55 Dec 19, 2022