masaldana2 masaldana2 - 1 year ago 86
iOS Question

Objective-c Property returns 'nil' in Swift 3


@property(nonatomic,readwrite) int count;


_count = 0; count++;


var audioSwift: audio?

This returns 'nil' and what I want is to have the modified valued


#import "audio.h"

What to do?
Thank you!

Answer Source

Don't post answers in comments.

Here is a complete answer:

The problem is that you never create an audio object, so your audioSwift variable is indeed nil.

Change your Swift code like this:

var audioSwift = audio()  //Create a new audio object. 

Since the code above creates an audio object right away, it doesn't need to be an Optional any more.

Note that in both Swift and Objective-C class names should start with an upper-case letter, so your audio class should be named Audio instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download