Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating to Swift 3 [Help wanted] #285

Closed
AnnieNinaJoyceV opened this issue Sep 23, 2016 · 13 comments
Closed

Migrating to Swift 3 [Help wanted] #285

AnnieNinaJoyceV opened this issue Sep 23, 2016 · 13 comments

Comments

@AnnieNinaJoyceV
Copy link

Here is my CoreData model
screen shot 2016-09-23 at 4 37 05 pm

for example JSON,

screen shot 2016-09-23 at 4 46 32 pm

Related code:

`func getFilmographyDetailsFromServer(completion: @escaping (NSError?) -> Void) {

    networkManager.bypassAuthentication()
    let hitURL = Service.baseURL + Service.path.getFilmoGraphy
    networkManager.manager!.request(hitURL, method: .get, parameters: nil)
        .responseJSON { response in
            if let data = response.result.value {
                let result =  data as! [String : AnyObject]
                if result["filmography"] != nil {
                    print(result["filmography"])
                    guard let filmography = result["filmography"] else {
                        return
                    }
                    let filmoResult = filmography as! [Dictionary<String, AnyObject>]
                    Sync.changes(filmoResult, inEntityNamed: "FilmographyCD", dataStack: self.dataStack, completion: { (error) in
                        completion(error)
                    })
                }
            } else {
                self.spotLoadView?.stopAnimation()
                self.spotLoadView?.isHidden = true
                self.showAlert(title: "Oops!!", message: (response.result.error?.localizedDescription)!)
            }
    }
}`

The same core data setup works fine without any issues in Xcode 7 & Swift 2
But in `Xcode 8 & Swift 3', it is crashing at this line,

~/Pods/Sync/Source/NSManagedObject+Sync.swift
let localItems = localRelationship.value(forKey: entity.sync_localPrimaryKey()) as? NSSet ?? NSSet()

With crash log,

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FilmographyDetailsCD 0x6000000ba1c0> valueForUndefinedKey:]: the entity FilmographyDetailsCD is not key value coding-compliant for the key "category".'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102c1834b exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000106bd821e objc_exception_throw + 48
2 CoreFoundation 0x0000000102c18299 -[NSException raise] + 9
3 CoreData 0x00000001027cf204 -[NSManagedObject valueForUndefinedKey:] + 308
4 Foundation 0x0000000106756d9e -[NSSet(NSKeyValueCoding) valueForKey:] + 417
5 Sync 0x00000001049f6798 TFE4SyncCSo15NSManagedObject23sync_toManyRelationshipfTCSo25NSRelationshipDescription10dictionaryGVs10DictionarySSP__6parentGSqS0__18parentRelationshipGSqS1__9dataStackC9DATAStack9DATAStack10operationsVC10DATAFilter10DATAFilter9Operation_T + 12424
6 Sync 0x00000001049f225a TFE4SyncCSo15NSManagedObject23sync_fillWithDictionaryfTGVs10DictionarySSP__6parentGSqS0__18parentRelationshipGSqCSo25NSRelationshipDescription_9dataStackC9DATAStack9DATAStack10operationsVC10DATAFilter10DATAFilter9Operation_T + 4090
7 Sync 0x0000000104a08bb6 TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSP___13inEntityNamedSS9predicateGSqCSo11NSPredicate_6parentGSqCSo15NSManagedObject_18parentRelationshipGSqCSo25NSRelationshipDescription_9inContextCSo22NSManagedObjectContext9dataStackC9DATAStack9DATAStack10operationsVC10DATAFilter10DATAFilter9Operation10completionGSqFGSqCSo7NSError_T___T_U0_FTGS1_SSP__S3__T + 198
8 DATAFilter 0x0000000103b526d6 TZFC10DATAFilter10DATAFilter7changesfTGSaGVs10DictionarySSP___13inEntityNamedSS9predicateGSqCSo11NSPredicate_10operationsVS0_9Operation15localPrimaryKeySS16remotePrimaryKeySS7contextCSo22NSManagedObjectContext8insertedFGS1_SSP__T_7updatedFTGS1_SSP__CSo15NSManagedObject_T__T + 7590
9 Sync 0x0000000104a0822e TZFC4Sync4Sync7changesfTGSaGVs10DictionarySSP___13inEntityNamedSS9predicateGSqCSo11NSPredicate_6parentGSqCSo15NSManagedObject_18parentRelationshipGSqCSo25NSRelationshipDescription_9inContextCSo22NSManagedObjectContext9dataStackC9DATAStack9DATAStack10operationsVC10DATAFilter10DATAFilter9Operation10completionGSqFGSqCSo7NSError_T___T + 3022
10 Sync 0x0000000104a060a5 TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSP___13inEntityNamedSS9predicateGSqCSo11NSPredicate_9dataStackC9DATAStack9DATAStack10operationsVC10DATAFilter10DATAFilter9Operation10completionGSqFGSqCSo7NSError_T___T_U_FCSo22NSManagedObjectContextT + 469
11 Sync 0x0000000104a0629f TPA__TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSP___13inEntityNamedSS9predicateGSqCSo11NSPredicate_9dataStackC9DATAStack9DATAStack10operationsVC10DATAFilter10DATAFilter9Operation10completionGSqFGSqCSo7NSError_T___T_U_FCSo22NSManagedObjectContextT + 255
12 DATAStack 0x0000000103b804c3 TFFC9DATAStack9DATAStack29performInNewBackgroundContextFFCSo22NSManagedObjectContextT_T_U_FT_T + 67
13 DATAStack 0x0000000103b80507 TTRXFo___XFdCb
+ 39
14 CoreData 0x0000000102763db7 developerSubmittedBlockToNSManagedObjectContextPerform + 199
15 libdispatch.dylib 0x0000000107e050cd _dispatch_client_callout + 8
16 libdispatch.dylib 0x0000000107de2e6b _dispatch_queue_serial_drain + 236
17 libdispatch.dylib 0x0000000107de3b9f _dispatch_queue_invoke + 1073
18 libdispatch.dylib 0x0000000107de407f _dispatch_queue_override_invoke + 683
19 libdispatch.dylib 0x0000000107de63b7 _dispatch_root_queue_drain + 720
20 libdispatch.dylib 0x0000000107de608b _dispatch_worker_thread3 + 123
21 libsystem_pthread.dylib 0x00000001081ae4de _pthread_wqthread + 1129
22 libsystem_pthread.dylib 0x00000001081ac341 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Any help is much appreciated to get this fixed. Thanks!

@pwestrich
Copy link

I think this might be similar to the problem I'm having in #280.

@3lvis
Copy link
Owner

3lvis commented Sep 24, 2016

Thanks for reporting this bug, @AnnieNinaJoyceV. I was able to reproduce it. #286

@3lvis
Copy link
Owner

3lvis commented Sep 24, 2016

@pwestrich Yeah, looks like they could be related.

@3lvis
Copy link
Owner

3lvis commented Sep 24, 2016

@AnnieNinaJoyceV I was able to reproduce, probably because I'm using id as primary key. What are your primary keys for this entities?

#286

@AnnieNinaJoyceV
Copy link
Author

@3lvis thank you for having a look on this issue. The original response doesn't have 'id' included. Thus mine has category and film as primary keys.

@3lvis
Copy link
Owner

3lvis commented Sep 24, 2016

Hi @AnnieNinaJoyceV I'm having a hard time reproducing this bug. Seems to be working fine from here.

#286

@3lvis
Copy link
Owner

3lvis commented Sep 24, 2016

Any ideas on what I could try to reproduce the crash?

@AnnieNinaJoyceV
Copy link
Author

@3lvis ah, I'm not sure.. Even it works for me if I use swift 2.3 branch. The live app uses 2.3 branch. Is there something I might have probably missed?

@AnnieNinaJoyceV
Copy link
Author

Or I will try to make a demo project and share by Monday?

@3lvis
Copy link
Owner

3lvis commented Sep 24, 2016

@AnnieNinaJoyceV I'll try to reproduce on the Swift 2.3 branch. If it works there as well, a demo project would be very useful.

Thanks for following up! Have a great weekend 🌻

@AnnieNinaJoyceV
Copy link
Author

Sure, great weekend to you too :)

@3lvis 3lvis added the bug label Sep 24, 2016
@AnnieNinaJoyceV
Copy link
Author

Hi @3lvis I hope you had a great weekend. Here is a very rough demo project for this issue - https://www.dropbox.com/s/mcmrigrnczxh5ku/Sync285.zip?dl=0
Please let me know after checking :)

@3lvis
Copy link
Owner

3lvis commented Sep 26, 2016

Thanks for supplying the demo project. I used it to verify that this was fixed on the latest Sync release.

Fixed on Sync 2.1.2

@3lvis 3lvis closed this as completed Sep 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants