Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swift core data order by

 func sortlist(){

    //1
    guard let appDelegate =
        UIApplication.shared.delegate as? AppDelegate else {
            return
    }

    let managedContext =
        appDelegate.persistentContainer.viewContext

    //2
    let fetchRequest =
        NSFetchRequest<NSManagedObject>(entityName: "User")
    let sort = NSSortDescriptor(key: "date", ascending: false)
    fetchRequest.sortDescriptors = [sort]

    //3
    do {
        let  langugeCodes = try managedContext.fetch(fetchRequest)
        for result in langugeCodes as [NSManagedObject] {
            var   username:String = result.value(forKey: "username")! as! String

            print("username==>",username)


        }


    } catch let error as NSError {
        print("Could not fetch. (error), (error.userInfo)")
    }
}
Comment

PREVIOUS NEXT
Code Example
Swift :: Rules for naming Swift Variables 
Swift :: xcode create image from calayer 
Swift :: appendBytes: Lengt: SWIFT 
Swift :: how to print body moya swift 
Swift :: fullscreencover swiftui 
Swift :: swift chuck array in peases 
Swift :: chevrondownf6a06a60-2122-49d0-86a0-03ba8c532aec 
Swift :: swift concurrency datatask before ios 15 
Swift :: xcode macosx have view resize when window size changed 
Swift :: xib image shown on simulator but not on device 
Swift :: how to get ride of back button in navbar xcode 
Swift :: jsonserialization swift 
Swift :: AndroidManifest.xml:5: Error: Class referenced in the manifest flutter build 
Swift :: Swift Fatal error when accessing a null unwrapped optional 
Swift :: swift 5 macos close app 
Swift :: swift array to data 
Swift :: how to add two right bar button item xcode 
Ruby :: 2 decimal places ruby 
Ruby :: brew update ruby 
Ruby :: ruby hash transform values 
Ruby :: ruby min 2 numbers 
Ruby :: rails logger color 
Ruby :: how to format date and time in rails 
Ruby :: rails form_tag 
Ruby :: generate csv ruby 
Ruby :: rails catch mail error 
Ruby :: rails convert unix timestamp to datetime 
Ruby :: run a rake task 
Ruby :: ruby conditionals 
Ruby :: how to upload a file in capybara spec 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =