Advertise here

Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Casting from String to NSManagedObject

markhardymarkhardy Los AngelesPosts: 7New Users Noob
Hi there,

I'm making an app that is going to put first name and phone number from the AddressBook framework into my app's Core Data when that contact is selected. This is my first Core Data app and I am struggling.

I'm trying to move the product of 'phones' (comes about when a user selects a contact) into an NSManagedObject called 'numbersArray' and am feeling a tad stuck as I've tried this several different ways.

Does anyone know how to correctly get that data into the NSManagedObject 'numbersArray'? I should be able to figure it out from there. Can post the rest of the code if needed.
        /* Get all phone numbers this user has */
        let phones: ABMultiValueRef = ABRecordCopyValue(person, kABPersonPhoneProperty).takeRetainedValue()
        let names: ABMultiValueRef = ABRecordCopyValue(person, kABPersonFirstNameProperty).takeRetainedValue()
        let countOfPhones = ABMultiValueGetCount(phones)
        for index in 0..<countOfPhones{
            phone = ABMultiValueCopyValueAtIndex(phones, index).takeRetainedValue() as! String
            numbersArray.append(phones as! NSManagedObject)
            namesArray.append(names as! NSManagedObject)


  • markhardymarkhardy Los AngelesPosts: 7New Users Noob
    PS: I've been getting the console error: Could not cast value of type '__NSCFString' (0x109b61c50) to 'NSManagedObject' (0x109300cd8).
Sign In or Register to comment.