Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 807
RyJ Avatar asked Oct 23 '15 19:10

RyJ


1 Answers

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.

like image 147
Jeepston Avatar answered Sep 23 '22 06:09

Jeepston