Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Khoa Nguyen KhoaVanNguyen

🏠
Working from home
Block or report user

Report or block KhoaVanNguyen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View exportToPdf.cs
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
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 guard demo.swift
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
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 using if let registering user.swift
if let username = usernameTF.text {
if let password = passwordTF.text {
// Do register user here
}else {
// Alert no password
}
}else {
// Alert no username
}
View How to reverse geocoding in IOS
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
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
if touches.first?.view != subView{
// subView is your view
dismiss(animated: true, completion: nil)
}
}
View Variadic Parameters
```swift
func printNames( names : String... ){
for name in names{
print(name)
}
}
printNames(names: "Swift","Go","Python","Java","C++")
```
View sayHelloTo
func sayHelloTo( parameter : String){
// use parameter in function
}
sayHelloTo(argument)
View findIndex of
func findIndex(of number : Int , in array : [Int] ) -> Int?{
for ( index, value ) in array.enumerated(){
if value == number {
return index
}
}
return nil
}
// call it
You can’t perform that action at this time.