小编Mru*_*ank的帖子

在swift中检索WKInterfaceLabel的文本

如何在WatchKit中获取Swift或Objective-C中的标签文本?
该类不是UILabel,而是WKInterfaceLabel.
我也尝试在苹果的类库中搜索,但只有三种方法可用.

label ios swift watchkit

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

Xcode 9.3 Git merge解决冲突后的问题

我从主分支中提取一些代码,但它包含与我的代码冲突.只有1个文件处于更改状态,只有1个更改,并且包含冲突.我通过选择"向右选择然后向左"解决它,但"拉"按钮未启用.它仍然被禁用.昨天我也遇到了同样的问题,但我忽略了.
现在又来了.这在Xcode 9.2中运行良好.我错过了什么或者我应该向Apple报告此错误吗?

这是截图. Xcode截图

git xcode git-merge-conflict xcode9.3

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

如何减少iOS中的应用程序大小?

我知道它已被多次询问,但每个答案建议使用压缩图像或链接到网络上的图像而不是资源包.
在我的应用程序中只有1.5 MB的图像,但仍然应用程序的大小为20.9 MB.

我的应用程序中的其他文件如下:

  • 2个框架(CoreLocation,CoreBluetooth)
  • 2个豆荚(面料,Crashlytics)
  • 8 xib
  • 2种字体(254KB)
  • 还有一些Swift和obj-c文件

任何人都可以帮我优化我的应用程序的大小?


我想知道为什么我的应用程序如此大,如果只有1.5 MB的图像和254 KB的字体?我的iPhone上有一些应用程序与我的应用程序具有相同的功能,它们只占用520 KB和1.6 MB.有谁知道这些应用程序的开发人员是如何实现的?

iphone optimization ios

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

在Swift中将字节数组转换为UIImage

我想将字节数组转换为UIImage我的项目.
为此我在这里找到了一些东西.
之后,我尝试在swift中转换该代码但失败了.

这是我的代码的快速版本.

func convierteImagen(cadenaImagen: NSMutableString) -> UIImage {
        var strings: [AnyObject] = cadenaImagen.componentsSeparatedByString(",")
        let c: UInt = UInt(strings.count)
        var bytes = [UInt8]()
        for (var i = 0; i < Int(c); i += 1) {
            let str: String = strings[i] as! String
            let byte: Int = Int(str)!
            bytes.append(UInt8(byte))
//            bytes[i] = UInt8(byte)
        }
        let datos: NSData = NSData(bytes: bytes as [UInt8], length: Int(c))
        let image: UIImage = UIImage(data: datos)!
        return image
    }
Run Code Online (Sandbox Code Playgroud)


但是我收到了错误:

EXC_BAD_INSTRUCTION

屏幕截图显示如下. …

arrays bytearray uiimage ios swift

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

当 swift iOS 中出现意外值时,如何将 nil 设置为可编码枚举

我正在使用Codable我的 WebRequest 响应,它返回一些预定义的字符串或数字。所以,我使用枚举来实现这些。但是,当一些意外值到达响应时,我的 Codable 无法解码。

这里有一些代码可以更好地理解。

class WebUser: Codable, Equatable {
    static func == (lhs: WebUser, rhs: WebUser) -> Bool {
        return lhs.id == rhs.id
    }
    ...
    var mobileNumberPrivacy: CommonPrivacyOption?
    var emailPrivacy: CommonPrivacyOption?
    var dobPrivacy: CommonPrivacyOption?
    ...
}

enum CommonPrivacyOption: Int, CaseIterable, Codable {
    case privacyOnlyMe = 1, privacyPublic, privacyFriends, privacyFriendsOfFriends

    //Does not help this optional init function
    /*init?(rawValue: Int) {
        switch rawValue {
            case 1: self = .privacyOnlyMe
            case 2: self = .privacyPublic
            case 3: self = …
Run Code Online (Sandbox Code Playgroud)

enums swift codable

6
推荐指数
2
解决办法
1961
查看次数

如何在图表中使用字符串值代替双精度值作为 X 轴?

我想通过使用“图表”在折线图中显示 X 轴的字符串值,我在这里遵循了相同的教程。正如那里所写,
let lineChartData = LineChartData(xVals: dataPoints, dataSet: lineChartDataSet)
我在当前最新版本的库中找不到。在当前库版本的演示代码中,我只能填充doubleX 轴和 Y 轴的数据类型。请帮我解决这个问题。
这是所需的输出。 折线图

ios swift ios-charts

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

将 .mov 附加到 MFMailComposeViewController

我想通过电子邮件发送 .mov 文件。所以我使用 MFMailComposeViewController。花了一些时间搜索后,我终于写了下面的代码。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *myPathDocs =  [documentsDirectory stringByAppendingPathComponent:
                                     [NSString stringWithFormat:@"/Saved Video/%@",[player.contentURL lastPathComponent]]];
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail addAttachmentData:[NSData dataWithContentsOfURL:[NSURL URLWithString:myPathDocs]] mimeType:@"video/quicktime" fileName:[myPathDocs lastPathComponent]];
[mail setSubject:@"Share VIDEO by My App"];
[self presentViewController:mail animated:YES completion:nil]; 
Run Code Online (Sandbox Code Playgroud)

当邮件编辑器出现时,我可以在邮件正文中看到附件,但我收到的这封邮件没有附件。
我错过了什么吗?或做错了什么?

请帮我。

email objective-c email-attachments ios mfmailcomposeviewcontroller

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

navigationController popToViewController 在 swift 3 中不起作用

我想使用popToViewControllernavigationController斯威夫特3.0。
为此,我写了下面的代码,但没有按预期工作。

let controllers = self.navigationController?.viewControllers
for vc in controllers! {
    if vc is HomeViewController {
        self.navigationController?.popToViewController(vc, animated: true)
    }
}
Run Code Online (Sandbox Code Playgroud)

我也写了下面的代码,但这也有效。

for vc in controllers! {
    if vc.isKind(of:HomeViewController.self) {
        self.navigationController?.popToViewController(vc, animated: true)
    }
}
Run Code Online (Sandbox Code Playgroud)

请帮我解决这个问题。

uinavigationcontroller ios swift3

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

以编程方式隐藏和显示WKInterfaceGroup

我正在使用xCode 6.2 beta 2并尝试以编程方式隐藏和显示组,但是没有显示我可以编写的方法group.hidden=YESgroup.hidden=NO 是否还有其他方法可以执行此操作?

objective-c ios apple-watch watchkit

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

acos和cos与度数没有给出正确的结果

我写下面的代码

NSLog(@"%f",acos(cos(1)));
Run Code Online (Sandbox Code Playgroud)


它返回1结果但是如果我试图从度而不是弧度获得结果然后面临如下问题

#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
NSLog(@"%f",acos(cos(DEGREES_TO_RADIANS(1)))); 
Run Code Online (Sandbox Code Playgroud)


然后它返回0.017453而不是1.
如果我写下面的话

NSLog(@"%f",acos(cos(DEGREES_TO_RADIANS(1)))*180/M_PI);
Run Code Online (Sandbox Code Playgroud)


然后我得到了正确1的结果.
但如果我写下面的话

NSString *a1 = [NSString stringWithFormat:@"%f",(cos(DEGREES_TO_RADIANS(1)))];
NSString *a2 = [NSString stringWithFormat:@"%f",(acos([a1 doubleValue])*180/M_PI)];
NSLog(@"%f",[a2 doubleValue]);
Run Code Online (Sandbox Code Playgroud)

然后我得到0.998999了结果.
然后问题在哪里?
请帮我

math trigonometry objective-c ios

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

没有从ios中的BLE设备获取数据/服务

我需要连接一个BLE设备,然后根据其中的不同按钮发送数据.
为此,我写了下面的代码.

import CoreBluetooth
class HomeViewController: UIViewController,CBPeripheralDelegate,CBCentralManagerDelegate 
{
    var centralManager : CBCentralManager!
    var peri : CBPeripheral!
    override func viewDidLoad()
    {
        super.viewDidLoad()
        centralManager = CBCentralManager(delegate: self, queue: nil)
    }
    func centralManagerDidUpdateState(central: CBCentralManager) {
        if central.state == .Unknown
        {
            print("Unknown")
        }
        else if central.state == .Unsupported
        {
            print("Unsupported")
        }
        else if central.state == .Unauthorized
        {
            print("Unauthorized")
        }
        else if central.state == .Resetting
        {
            print("Resetting")
        }
        else if central.state == .PoweredOn
        {
            print("Powered On")
            startScan()
        }
        else if central.state == .PoweredOff
        {
            print("Powered …
Run Code Online (Sandbox Code Playgroud)

ios core-bluetooth bluetooth-lowenergy swift

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