Xcode 7.1: Property with retain or strong attribute must be of object type
Asked Answered
F

2

8

I have this variable in a swift file:

var adbk: ABAddressBook!

Which has always been fine, until Xcode 7.1. Now it complains "Property with retain or strong attribute must be of object type." The error is in the -Swift.h file. Any idea what got changed that would cause this and how to fix it?

Floydflss answered 23/10, 2015 at 19:10 Comment(7)
Shouldn't you store a ABAddressBookRef instead? ABAddressBook is a struct. Either get rid of the ! by assigning it in init or use a ? if it might not be set.Longevity
It can be nil at times. I changed it to a ? and still get the same error. And changing it to ABAddressBookRef doesn't help either.Floydflss
This may be Apple's subtle way of forcing me to transition to CNContactStore.Floydflss
How about it you change it to let or private var, any difference?Sebaceous
Oh nice, private var worked! Thanks!Floydflss
Keep in mind the semantics for using access modifers too! https://mcmap.net/q/442751/-private-var-is-accessible-from-outside-the-classSebaceous
But why does private var work?Longevity
I
3

This error occurs if Swift class declares some of the AdressBook properties and this class is part of the mixed Swift / ObjC project. Xcode then generate Swift bridging header, where this property becomes (nonatomic, strong), which is applicable to objects only, not structures.

I have encountered similar issue when I needed to pass ABRecordRef from Objective-C class to Swift class: Xcode didn't like my ABRecordRef property in Swift. So I've ended up making that property private, so that it is not exported to the bridging header, and adding new method in Swift class to receive ABRecordRef:

    class: PersonDetails {

       private var selectedPerson: ABRecorfRef?

       func setPerson(person: ABRecordRef) {
          selectedPerson = person
       }
    }

And then you can call

[personDetails setPerson: person];

from Objective-C class.

Intramural answered 20/11, 2015 at 21:27 Comment(0)
P
0

ABAddressBook is deprecated

@available(iOS, introduced=2.0, deprecated=9.0, message="use CNContactStore")
public typealias ABAddressBookRef = ABAddressBook

so i think you have to use CNContactStore

Pharyngology answered 15/12, 2015 at 5:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.