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

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?


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.


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

链接地址: http://www.djcxy.com/p/29932.html

上一篇: 修改R因子?

下一篇: Xcode 7.1:带有retain或strong属性的属性必须是对象类型