delegating-constructor
全部标签 想听听您对以下架构的看法:在我的应用程序中,我有一个处理异步登录的静态类(LoginManager)。一旦登录阶段完成,应用程序应该响应并转换到另一个状态。我有2个实现建议使用委托(delegate):importFoundationprotocolLoginManagerDelegate{funconLogin(result:AnyObject)}classLoginManager{structWrapper{staticvardelegate:LoginManagerDelegate?}classfuncuserDidLogin(result){Wrapper.delegate?.
我目前正在尝试使用UIPresentationController呈现ViewController。我的问题是,当我的自定义转换委托(delegate)调用funcpresentationControllerForPresentedViewController(presented:UIViewController,presentingViewControllerpresenting:UIViewController!,sourceViewControllersource:UIViewController)->UIPresentationController?我的呈现Controller
我在用纯Swift创建东西时遇到了问题。我正在尝试实现类似于NSValueTransformer的类注册表。在Objective-C中,我将通过在子类的load类方法中调用setValueTransformer:forName:来确保NSValueTransformer子类已注册。这种方法在Swift中不起作用,因为运行时不会在Swift类上调用load。我的下一个想法是找到__attribute__((constructor))的Swift版本,但我的搜索一无所获。Swift是否提供类似于__attribute__((constructor))的东西,或者是实现此目的的唯一方法是编写
我已经定义了一个带有返回元组方法的协议(protocol):protocolSMCalculatorDelegate{funcnumbersToAdd()->(Int,Int)}当我尝试像这样针对我的类中的委托(delegate)方法调用它时:classSMCalculator:NSObject{vardelegate:SMCalculatorDelegate?funcadd(){letmyTuple:(n1:Int,n2:Int)=delegate?.numbersToAdd()}}我在引用该行代码的.numbersToAdd()部分的letmyTuple...开头的行中收到以下错误
我有一个UIViewControllerclassWelcomeViewController:UIViewController和一个UIViewclassSignUpView:UIView现在我想在SignUpView的WelcomeViewController委托(delegate)中设置:protocolSegueDelegate{funcrunSegue(identifier:String)}classSignUpView:UIView{...}并将其连接到classWelcomeViewController:UIViewController,SegueDelegate{我如何在
我需要一个仅在系统检测到没有互联网连接时运行的函数,然后在系统检测到互联网连接时运行另一个函数。我在想这样的事情:funconInternetConnection(){//Enableactions}funconInternetDisconnection(){//Disableactions,alertuser}我还需要一种检测系统何时重新连接的方法,以便让用户知道它正在重新连接,就像在Facebook的Messenger中一样。我该怎么做?我正在为我的网络层使用Moya/Alamofire。 最佳答案 这适用于Alamofirei
这个问题在这里已经有了答案:swiftios-HowtorunfunctioninViewControllerfromAppDelegate(2个答案)关闭5年前。我的ViewController有很多初始化的方法和变量。当我的应用程序进入后台时,我需要从应用程序委托(delegate)访问ViewController中的特定值。我已尝试在应用程序委托(delegate)中执行此操作:vc=ViewController()...但这创建了一个新实例,并且值基本上设置为新的。
我想对我的3个案例进行切换,但我遇到了无法解决的错误:错误:在类型名称之后需要成员名称或构造函数调用自从我一直在使用类似的代码以来,一定有什么地方被我忽略了。但是现在我的项目几乎是空的,无法弄清楚出了什么问题?importUIKitclassViewController:UIViewController{enumMyStateStatus{caseReadycaseRunningcaseStopped}@IBActionfuncactionPressed(sender:UIButton){switchMyStateStatus{caseMyStateStatus.Ready:print
变量不是nil,我的连接很好,url是正确的,但没有调用委托(delegate)方法。我也在实现WebSocketDelegateletsocket=WebSocket(url:NSURL(string:"UrlHere:port/")!)socket.delegate=self;socket.connect()ifsocket.isConnected{print("websocketisconnected")}funcwebsocketDidConnect(ws:WebSocket){print("websocketisconnected")}funcwebsocketDidDisc
我的iOS应用程序通过WatchConnectivity框架发送及时的信息。接收方实现WCSession的委托(delegate)。我有2个interfaceControllers需要从WCSession发送的信息。一个是glanceInterfaceController,另一个是我的mainInterfaceController。是否可以为它们都分配委托(delegate)并同时接收从我的iOS应用程序发送的userInfo或applicationContext?或者只能分配一个WCSession委托(delegate),而我的Controller需要从分配的对象中获取数据?谢谢!