View .swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var query: NSMetadataQuery? { | |
willSet { | |
if let query = self.query { | |
query.stop() | |
} | |
} | |
} | |
public func doSpotlightQuery() { | |
query = NSMetadataQuery() |
View exportToPdf.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string GeneratePdfWithOffice(string sourceUrl, string pdfPath, string lookupCode) | |
{ | |
try | |
{ | |
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application(); | |
app.Visible = false; | |
Microsoft.Office.Interop.Excel.Workbook wkb = app.Workbooks.Open(sourceUrl); | |
wkb.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, pdfPath); | |
wkb.Close(); | |
app.Quit(); |
View validation using guard.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func login() { | |
guard let username = usernameTF.text, isValid(username: username) else { | |
// wrong username format | |
return | |
} | |
// do register here | |
} | |
func isValid(username: String) -> Bool { | |
// check username trùng |
View using if let registering user.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if let username = usernameTF.text { | |
if let password = passwordTF.text { | |
// Do register user here | |
}else { | |
// Alert no password | |
} | |
}else { | |
// Alert no username | |
} |
View using guard demo.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guard DataService.ds.introImage != nil else { | |
showAlert(title: Settings.General.appName, message: Settings.Error.noIntroImage) | |
return | |
} | |
guard DataService.ds.photoImage != nil else { | |
showAlert(title: Settings.General.appName, message: Settings.Error.noPhotoImage) | |
return | |
} | |
guard DataService.ds.videoImage != nil else { | |
showAlert(title: Settings.General.appName, message: Settings.Error.noVideoImage) |
View using guard let register user.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guard let username = usernameTF.text, username.characters.count >= 6 else { | |
// wrong username format | |
return | |
} | |
guard let password = passwordTF.text, password.characters.count >= 6 else { | |
// wrong password format | |
return | |
} | |
// do register user here |
View Variadic Parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```swift | |
func printNames( names : String... ){ | |
for name in names{ | |
print(name) | |
} | |
} | |
printNames(names: "Swift","Go","Python","Java","C++") | |
``` |
View How to reverse geocoding in IOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func reserveGeo(){ | |
let geoCoder = CLGeocoder() | |
geoCoder.reverseGeocodeLocation(userLocation, completionHandler: { (placemarks, error) in | |
guard let addressDict = placemarks?[0].addressDictionary else { | |
return | |
} | |
if let formattedAddress = addressDict["FormattedAddressLines"] as? [String] { | |
let address = formattedAddress.joined(separator: ", ") | |
// set value to your control |
View hide a view by touching outside of it in IOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){ | |
if touches.first?.view != subView{ | |
// subView is your view | |
dismiss(animated: true, completion: nil) | |
} | |
} |
View findIndex of
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func findIndex(of number : Int , in array : [Int] ) -> Int?{ | |
for ( index, value ) in array.enumerated(){ | |
if value == number { | |
return index | |
} | |
} | |
return nil | |
} | |
// call it |
NewerOlder