小编Jie*_* Hu的帖子

如何使用Contacts Framework获取iOS 9中的所有联系人记录

在iOS 9中不推荐使用AddressBook框架的大部分内容.在新的Contacts Framework 文档中,只显示了如何获取与a匹配的记录NSPredicate,但如果我想要所有记录呢?

contacts nspredicate ios ios9

74
推荐指数
9
解决办法
6万
查看次数

如何在swift中正确传递选择器作为参数

最后说

我有一个包含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)

selector ios swift

19
推荐指数
1
解决办法
1万
查看次数

在Xcode中启用代码折叠栏

如何启用行号旁边的代码折叠栏?

我用谷歌搜索"代码折叠Mac"; 这一切都是关于触发代码折叠和展开,但没有关于启用条形码.

我曾尝试使用Editor -> Code Folding -> Fold/Unfold折叠和展开代码,但我没有在行号旁边的垂直条; 所以,我有按钮点击折叠和展开.

我该如何启用该栏?

请在此处查看图片.

xcode code-folding ios

18
推荐指数
3
解决办法
2869
查看次数

WCSession.sendMessage工作50/50

最近,我正在研究一个与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)

ios swift watchos-2

10
推荐指数
1
解决办法
7744
查看次数

watchOS 2是否具有Force Touch的API?

作为标题,我想要确定是否WKInterfaceButton正常点击或强制点击.现在通过watchOS 2可以实现吗?

apple-watch wkinterfacebutton watchos-2

5
推荐指数
1
解决办法
810
查看次数

如何在Swift中为特定类型的数组进行扩展

比方说我有:

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)

swift

5
推荐指数
1
解决办法
1157
查看次数

在watch os 2中运行时更新wkinterfacecontroller的方法

在头文件中

#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)

但是,它似乎没有更新.有没有适当的更新方式?

objective-c watchkit watchos-2

3
推荐指数
1
解决办法
1264
查看次数

Objective-C语法:<>

@interface A : B<C>
@interface ViewController : UIViewController<MSBClientManagerDelegate>
Run Code Online (Sandbox Code Playgroud)

所以我想我得到A是B的子类,而B是A的超类,但是B和C之间的关系是什么?

syntax objective-c

1
推荐指数
1
解决办法
43
查看次数