简体   繁体   中英

access NSMutableArray(objective c) from swift viewcontroller

I been stuck for days and I want to access and modify my already initialized NSMutableArray from the swift view controller.

seq.m

init()

 _sequence = [NSMutableArray arrayWithObjects: @(false),@(true),@(true), nil]; 

seq.h

@property(nonatomic,strong,readwrite) NSMutableArray * _Nonnull sequence;

viewController.swift

var audio3:seq?

viewDidLoad()

audio3?.sequence = [true,false,true]

print(audio3?.sequence)

Bridging-header.h

#import "seqTest.h"

all I got is ' nil ' as result

what am I doing wrong?

As far as I can tell from your code snippets, your audio3 variable is not initialized. Try var audio3 : seq? = seq() var audio3 : seq? = seq() instead of var audio3 : seq? .

The way your original code is, the audio3 variable is uninitialized, so the initializer init() , where the property sequence is set up, is never called for that variable. You get a nil because audio3 itself is nil . You could verify that using code like this:

if let x = audio3
{
    print(x.sequence)
}
else{
    print ("x is not initialized")
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM