ios


fetching results from core data in one to many relationship


All related questions I saw are in Objective C, but I use Swift.
I have a one to many relationship in core data, one "Current" entity to many "Forecast" entities. I manage to save and get the "Current" entity, but fail to do it for the "matching"for my table "Forecast" entities. The Forecast entities should also be displayed in a UITableView.
This is what I have by now. The array I'm trying to create is always empty. I need some help here:
guard let stack = (UIApplication.shared.delegate as! AppDelegate).stack else {return}
let sortDescriptors = [NSSortDescriptor(key: "city_id_forecast", ascending: true)]
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Forecast")
fetchRequest.sortDescriptors = sortDescriptors
fetchRequest.predicate = NSPredicate(format: "main==%#", currentFetched!)
if (currentFetched==nil){
print("current fetched is nil")
}
else{
print("currentFetched is not nil")
}
let fetchedResultController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: stack.context, sectionNameKeyPath: "city_id_forecast", cacheName: nil)
do {try fetchedResultController.performFetch()}
catch {print ("error in performing fetch results\(error)")}
let fetched = fetchedResultController.fetchedObjects
//let fetched = fetchedResultController.
let count = fetched?.count
print ("count of fetched forecast!: \(count!)")
for i in 0..<count!{
let currentFetched = fetched?[i] as? Forecast
let dateForecast = currentFetched?.value(forKeyPath: "date_forecast") as! String
let tempForecast = currentFetched?.value(forKeyPath: "temperature_forecast") as! String
let iconForecast = currentFetched?.value(forKeyPath: "icon_forecast") as! String
let forecastElement = "\(dateForecast), \(tempForecast), \(iconForecast)"
forecastArray.append(forecastElement)

Related Links

How can I follow Artist and users using Apple Music
How to concatenate NSURL in Objective-c .? [duplicate]
resize UIImageView at rotation fluidly
iOS How can I get wifi list around my phone?
What version of Swift should i be using? [duplicate]
Modifying EKParticipantStatus in EventKit
Unknow exception that one IBAction selector have been used by unknown types for many times
How to get Firebase User (fb auth) directly? (without realtime db ref) [duplicate]
Cannot assign value of type NSManagedObject to type 'Journal' (an entity)
Download pdf file from url
How to authenticate user with token (stay authenticated in iPhone)
Swift - Thumbnail creation Memory Crash
No audio with Octane.Xam.VideoPlayer
NSSingleObjectArrayI error when JSON Parsing in iOS?
Post a data/image to facebook wall using access token in iOS
ERROR ITMS-90046: Invalid Code Signing Entitlements for embedded frameworks from cocoapods

Categories

HOME
vb.net
dom
hortonworks-data-platform
copy
configuration
watson
path
datetime
windows-runtime
runtime-error
ibm-midrange
wget
android-vision
executable
axure
nservicebus
cloudrail
fbx
installer
records
flow
round-robin
garmin
html-email
nested-set-model
cadvisor
confidence-interval
rrd
simple-html-dom
android-arrayadapter
webfocus
rdf4j
kubernetes-go-client
petrel
increment
apartment-gem
dxgi
ulimit
tern
backwards-compatibility
powerpc
pseudo-element
move
name-mangling
multistore
html-lists
typesetting
ice
column-oriented
jvm-arguments
waf
mapr
db2400
masspay
turbo-c
shift-reduce-conflict
cakephp-2.3
tfs2008
nsd
bootstrap-slider
webpagetest
finalcut
jstorm
webpack-hmr
administrator
multiple-files
genetic
folder-structure
phone-number
axlsx
sql-server-ce-3.5
llvm-gcc
java-client
isql
eventmachine
tinkerpop-frames
hobbitmon
keymapping
tlb
data-dictionary
batman.js
bochs
libnids
mips64
sugar.js
mms-gateway
sender
hiphop
adaboost
noindex
letter-spacing
jdic
myisam
custom-protocol
coords

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App