Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

store array in userdefaults swift

var defaults = UserDefaults.standard
var itemArray = ["Find Mike", "Buy Eggs","Buy Apple"]

override func viewDidLoad() {

        super.viewDidLoad()
        //First Way
        
        if let items  =  defaults.array(forKey: "TodoListArray") as? [String] {
            itemArray = items
        }
        // Second Way
        // itemArray = defaults.stringArray(forKey: "TodoListArray") ?? []
        
    }


    @IBAction func addButtonPressed(_ sender: UIBarButtonItem) {
        
        var addedItems = UITextField()
        
        let alert = UIAlertController(title: "Add New Item", message: "", preferredStyle: .alert)
        
        let action = UIAlertAction(title: "Add Item", style: .default) { action in
            //What to do when user pressed the (Add Item)
            self.itemArray.append(addedItems.text!)
            self.defaults.set(self.itemArray, forKey: "TodoListArray")
            self.tableView.reloadData()
        }
Comment

PREVIOUS NEXT
Code Example
Typescript :: how to extract digits of a number in c 
Typescript :: mat auto complete floating issue 
Typescript :: copy elements from one array to another java 
Typescript :: crashlytics ionic 3 
Typescript :: react native ios safe area padding not working 
Typescript :: see sheets of excel file python 
Typescript :: typescript add one month to date 
Typescript :: get ids of array of objects 
Typescript :: remote events client to server lua 
Typescript :: get angular width 
Typescript :: typescript string contains 
Typescript :: serving vue3 in django 
Typescript :: mat stepper dont clickable 
Typescript :: get ip add in react 
Typescript :: find number of digits in a number 
Typescript :: File C:UsersPraveenAppDataRoaming pm g.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. 
Typescript :: window open blob 
Typescript :: running scripts is disabled on this system 
Typescript :: echarts is not defined 
Typescript :: typescript filter list by property 
Typescript :: ng-select disabled 
Typescript :: react-native.ps1 cannot be loaded because running scripts is disabled on this system 
Typescript :: reactnative upload image axios 0.66 
Typescript :: import openzeppelin contracts in remix 
Typescript :: google sheets reference cell static 
Typescript :: typescript react dispatch 
Typescript :: typeorm query builder update relations filed 
Typescript :: check if a date is before another date in typescript 
Typescript :: mat-sort not working in dynamically generated table 
Typescript :: laravel unique working with softdeletes 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =