Skip to content

Instantly share code, notes, and snippets.

View novinfard's full-sized avatar

Soheil Novinfard novinfard

View GitHub Profile
@novinfard
novinfard / disabledTestProjUT.swift
Created July 8, 2021 11:02
[Disabled test result in project file structure - .xcodeproj] #unitTest
<SkippedTests>
<Test
Identifier = "MyTestClass/test_method_name()">
</Test>
</SkippedTests>
@novinfard
novinfard / setupTeardownMethodsUT.swift
Last active July 8, 2021 12:27
[Different setup and tear down initialisers] #unitTest
class MyTestClass: XCTestCase {
// get called before first test begins
override class func setUp() {
super.setup()
// do something
}
// get called before running each of the test cases in the class
override func setUp() {
@novinfard
novinfard / correctRTLLayout-SwiftUI.swift
Created June 29, 2021 09:55
[Correct RTL layout in SwiftUI]
struct BlogView: View {
let text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
var body: some View {
VStack(spacing: 16) {
Text("Blog Title")
.font(.title)
Text(text)
@novinfard
novinfard / swiftui-sample-english-number.swift
Created June 29, 2021 01:25
[Update SwiftUI app to demonstrate English number converter]
var body: some View {
VStack(spacing: 16) {
Text(text)
HStack {
Spacer()
.frame(width: 16)
image
Spacer()
}
@novinfard
novinfard / convertNumberToEnglishInt.swift
Created June 29, 2021 01:20
[Convert numbers to English and Integer type]
extension String {
var toEnglishNumberInt: Int? {
let formatter: NumberFormatter = NumberFormatter()
formatter.locale = NSLocale(localeIdentifier: "EN") as Locale?
guard let final = formatter.number(from: self) else { return nil }
return Int(truncating: final)
}
}
@novinfard
novinfard / swiftUIPreviewRTL-LTR.swift
Last active June 29, 2021 00:50
[SwiftUI preview in RTL and LTR]
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Group {
ContentView()
.environment(\.layoutDirection, .leftToRight)
.previewDisplayName("Left to Right")
ContentView()
.environment(\.layoutDirection, .rightToLeft)
.previewDisplayName("Right To Left")
@novinfard
novinfard / detectRTLInViews-SwiftUI.swift
Created June 29, 2021 00:36
[Detect RTL in SwiftUI views]
struct ContentView: View {
let text = "این یک متن تست است. در این متن به بررسی عملکرد زبان های راست به چپ می‌پردازیم."
@Environment(\.layoutDirection) var direction
var body: some View {
VStack(spacing: 16) {
Text(text)
HStack {
Spacer()
@novinfard
novinfard / detectRTLInViews-UIKit.swift
Last active June 29, 2021 00:25
[Detect RTL in UIKit views]
override func viewDidLoad() {
super.viewDidLoad()
let image = UIImage(systemName: "pencil.circle.fill")
if self.view.effectiveUserInterfaceLayoutDirection == .rightToLeft {
imageView.image = image?.imageFlippedForRightToLeftLayoutDirection()
} else {
imageView.image = image
}
}
@novinfard
novinfard / rotateImageSwiftUI.swift
Created June 29, 2021 00:01
[Rotated Image in SwiftUI]
Image(systemName: "pencil.circle.fill")
.resizable()
.frame(width: 100, height: 100)
.rotationEffect(.degrees(90))
@novinfard
novinfard / SwiftUISampleView-rtl-article.swift
Last active June 28, 2021 23:49
[SwiftUI sample view for RTL article]
import SwiftUI
struct ContentView: View {
let text = "این یک متن تست است. در این متن به بررسی عملکرد زبان های راست به چپ می‌پردازیم."
var body: some View {
VStack(spacing: 16) {
Text(text)
HStack {
Spacer()