How to create a simple text file in your iOS App? - Xcode tutorial using swift language

preview_player
Показать описание
This Video shows simple steps to create a text file from your iOS App. It shows the simple swift code which is written to do create the file in the document directory of the iPhone. It uses Xcode environment to develop and simulate the App in the in-built simulator. It shows the creation of the text file by navigating to the device folder in the library of the Mac OS (host OS) but in the real phone the file should get created in the document folder.

Complete source code and other details can be found in the below link:

However, the main swift code is copied below also for reference:

//
// Text File Creation App
//
// Created by HomePC on 29/10/20.
// Copyright © 2020 HomePC. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
// Dispose of any resources that can be recreated.
}


@IBAction func buttonCreate(Sender: UIButton){

let stringToWrite = "This is my demo string by programmer world"


do{

print("Successful - file written")
}
catch _{
print("Error")
}

}

}

}
Рекомендации по теме
Комментарии
Автор

Hi, Thanks for this valuable video. Can we save text files outside the app document directory for the MAC application (Cocoa application)?

theyashikashow
Автор

Thanks for your explanation. Do you know how to create de file in the device? To make it available for the app? Greetings from Brazil

marcellolima
welcome to shbcf.ru