Tag: 语法

Swift'open'关键字和可重写的方法/属性的扩展名?

在Swift 3.0中引入了open关键字(Swift 中的'open'关键字是什么? 注意:仅限于NSObject派生类或@objc属性方法/属性的扩展。 在public模块/框架之间扩展的public ( class )方法/属性的代码被破坏,因为public不再意味着定义模块之外的“可覆盖”。 例: public extension UIManagedDocument { public class func primaryDocumentName() -> String { return "Document" } public class func primaryStoreURL() -> URL { let documentsURL = FileManager.default.userDocumentsURL return URL(fileURLWithPath: self.primaryDocumentName(), isDirectory: false, relativeTo: documentsURL) } public class func primaryModelName() -> String? { return "Model" } } 原始提案( SE-0117 […]

Swift:如何解决types为“protocol”的弱variables是非法的问题

在阅读了关于这个问题的一些post之后,我发现我的协议应该从'class'inheritance,以便'weak'在我的委托variables上工作。 “弱”可能只适用于类或类绑定的协议types。 如果我的协议不从“类”inheritance,是否迅速“推断”它应该是弱? 这是铸造“协议”types的variables变弱的事实上的方式? 内存pipe理方面会发生什么? protocol FacebookLoginViewControllerDelegate: class { func facebookLoginViewControllerDidLogin(controller: FacebookLoginViewController) } class FacebookLoginViewController: UIViewController { weak var delegate: FacebookLoginViewControllerDelegate? }

奇怪的Objective-C语法 – 方括号和@符号

我在我的一个项目中使用GHSidebarNav,我碰到这个代码分配一个对象的数组。 我只是不知道它在做什么。 它只是一个数组? 这个奇怪的语法是什么? 我之前没有看到: NSArray *controllers = @[ @[ [[UINavigationController alloc] initWithRootViewController:[[GHRootViewController alloc] initWithTitle:@"Profile" withRevealBlock:revealBlock]] ], @[ [[UINavigationController alloc] initWithRootViewController:[[GHRootViewController alloc] initWithTitle:@"News Feed" withRevealBlock:revealBlock]], [[UINavigationController alloc] initWithRootViewController:[[GHMessagesViewController alloc] initWithTitle:@"Messages" withRevealBlock:revealBlock]], [[UINavigationController alloc] initWithRootViewController:[[GHRootViewController alloc] initWithTitle:@"Nearby" withRevealBlock:revealBlock]], [[UINavigationController alloc] initWithRootViewController:[[GHRootViewController alloc] initWithTitle:@"Events" withRevealBlock:revealBlock]], [[UINavigationController alloc] initWithRootViewController:[[GHRootViewController alloc] initWithTitle:@"Friends" withRevealBlock:revealBlock]] ] ];