在iOS 9中不推荐使用AddressBook框架的大部分内容.在新的Contacts Framework 文档中,只显示了如何获取与a匹配的记录NSPredicate,但如果我想要所有记录呢?
最后说
我有一个包含B实例的A类.在A类中,我将A的一个函数作为选择器传递给一个B的方法.B使用这个选择器来注册通知.但是,当通知进入时,它无法运行选择器并显示"无法识别的选择器发送到实例".如果我把我想要在B级做的所有事情都转移到A级,那就有用了.但是,我希望它们分开,以使它看起来更有条理.我对Objective-C和Swift相当新,因此,在这种情况下,我不知道如何将selector作为参数传递.Swift中的答案会很棒.
ViewController.swift
class ViewController: UIViewController {
var sessionCtrl : GKSessionControllerH!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
sessionCtrl = GKSessionControllerH()
// register notifications
registerNotification()
}
func registerNotification() {
sessionCtrl.registerNotification(GKGesture.Up, gestureHandler: "gestureUpHandler")
}
func gestureUpHandler() {
dispatch_async(dispatch_get_main_queue()) {
self.slidesViewCtrl!.prevPage()
}
}
}
Run Code Online (Sandbox Code Playgroud)
GKSessionControllerH.swift
class GKSessionControllerH: NSObject, WCSessionDelegate {
func handleGestureContent(content : AnyObject?) {
// retrieve gesture
let gesture = GKGesture(rawValue: content as! String)!
print("Handheld device receives \(gesture)")
// post …Run Code Online (Sandbox Code Playgroud) 如何启用行号旁边的代码折叠栏?
我用谷歌搜索"代码折叠Mac"; 这一切都是关于触发代码折叠和展开,但没有关于启用条形码.
我曾尝试使用Editor -> Code Folding -> Fold/Unfold折叠和展开代码,但我没有在行号旁边的垂直条; 所以,我有按钮点击折叠和展开.
我该如何启用该栏?
.
最近,我正在研究一个与Watch/ iPhone通信有关的项目.但是我的代码有时工作并且有时不起作用,这对我来说有点奇怪,因为我认为代码应该工作与否.它不能是50/50.因此,我不知道出了什么问题.
在iPhone上设置WCSession:
class WatchCommunicationController: NSObject, WCSessionDelegate {
var session : WCSession?
override init(){
// super class init
super.init()
// if WCSession is supported
if WCSession.isSupported() { // it is supported
// get default session
session = WCSession.defaultSession()
// set delegate
session!.delegate = self
// activate session
session!.activateSession()
} else {
print("iPhone does not support WCSession")
}
}
... ...
}
Run Code Online (Sandbox Code Playgroud)
Watch上类似的WCSession设置:
class PhoneCommunicationController: NSObject, WCSessionDelegate {
var session : WCSession?
override init(){
// super class init
super.init()
// if …Run Code Online (Sandbox Code Playgroud) 作为标题,我想要确定是否WKInterfaceButton正常点击或强制点击.现在通过watchOS 2可以实现吗?
比方说我有:
struct S {
var num = 0
}
Run Code Online (Sandbox Code Playgroud)
我想实现一个函数allEqual()作为扩展Array<S>,所以我可以做的事情
var s1 = S()
var s2 = S()
var s3 = S()
var equality = [s1,s2,s3].allEqual()
Run Code Online (Sandbox Code Playgroud) 在头文件中
#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>
#import <WatchConnectivity/WatchConnectivity.h>
@interface InterfaceController : WKInterfaceController<WCSessionDelegate>
- (IBAction)lastSongButtonClick;
- (IBAction)playSongButtonClick;
- (IBAction)nextSongButtonClick;
@property (strong, nonatomic) IBOutlet WKInterfaceLabel *songTitleLabel;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *playSongButton;
@end
Run Code Online (Sandbox Code Playgroud)
所以我实现了WCSessionDelegate,每次收到关于UI的内容时,我都希望它能够更新.所以在我的.m文件中我有:
- (void)session:(nonnull WCSession *)session didReceiveMessage:(nonnull NSDictionary<NSString *,id> *)message{
NSString* type = [message objectForKey:@"type"];
if([type isEqualToString:@"UIUpdateInfo"]){
NSLog(@"?Watch receives UI update info");
[self handleUIUpdateInfo:[message objectForKey:@"content"]];
}
}
Run Code Online (Sandbox Code Playgroud)
和
- (void)handleUIUpdateInfo:(NSDictionary*)updateInfo{
[self.songTitleLabel setText:[updateInfo objectForKey:@"nowPlayingSongTitle"]];
[self.playSongButton setBackgroundImage:[updateInfo objectForKey:@"playButtonImage"]];
}
Run Code Online (Sandbox Code Playgroud)
但是,它似乎没有更新.有没有适当的更新方式?
@interface A : B<C>
@interface ViewController : UIViewController<MSBClientManagerDelegate>
Run Code Online (Sandbox Code Playgroud)
所以我想我得到A是B的子类,而B是A的超类,但是B和C之间的关系是什么?
ios ×4
swift ×3
watchos-2 ×3
objective-c ×2
apple-watch ×1
code-folding ×1
contacts ×1
ios9 ×1
nspredicate ×1
selector ×1
syntax ×1
watchkit ×1
xcode ×1