如何从NSObject访问SceneDelegate?

时间:2020-05-14 04:32:22

标签: ios objective-c swift

我在sceneDelegate中声明了一个变量,并想从NSObject访问该变量。我们可以从UIView或UIViewController做到这一点,但是不知道如何在NSObject中做到这一点。

是否可以访问此变量?

1 个答案:

答案 0 :(得分:0)

如果应用程序中只有一个场景,则可以使用

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "Workaround")]
    public class ModelDiffer : MigrationsModelDiffer
    {
        public ModelDiffer(
            IRelationalTypeMappingSource typeMappingSource, 
            IMigrationsAnnotationProvider migrationsAnnotations, 
            IChangeDetector changeDetector,
            IUpdateAdapterFactory updateAdapterFactory, 
            CommandBatchPreparerDependencies commandBatchPreparerDependencies) :
            base(typeMappingSource, migrationsAnnotations, changeDetector, updateAdapterFactory, commandBatchPreparerDependencies)
        {
        }
        //FIXME Remove when https://github.com/aspnet/EntityFrameworkCore/issues/18943 is deployed
        public override IReadOnlyList<MigrationOperation> GetDifferences(IModel source, IModel target)
        {
            return base.GetDifferences(source, target)
                    .Where(o => !(o is UpdateDataOperation))
                    .ToList();
        }
    }

    services.AddDbContextPool<Context>(o =>
    {
        o.ReplaceService<IMigrationsModelDiffer, ModelDiffer>();
        o.UseSqlServer(connectionString, ...
    }