我一直试图转换这个代码,我从这个例子(在Objective-c中)没有运气.
String *path; // contains the file path
// Get the UTI from the file's extension:
CFStringRef pathExtension = (__bridge_retained CFStringRef)[path pathExtension];
CFStringRef type = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, NULL);
CFRelease(pathExtension);
// The UTI can be converted to a mime type:
NSString *mimeType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass(type, kUTTagClassMIMEType);
if (type != NULL)
CFRelease(type);
Run Code Online (Sandbox Code Playgroud)
我的代码是这样的
import MobileCoreServices
let path: String?
let pathExt = path.pathExtension as CFStringRef
let type = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, NULL);
let mimeType = UTTypeCopyPreferredTagWithClass(type, kUTTagClassMIMEType)
if type != Null …Run Code Online (Sandbox Code Playgroud) 我一直在努力实现获取完成块而没有运气.每当我发送一个APN时,xcode仍然会抱怨它没有实现.这是我的代码
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
println("2. User Data", userInfo)
completionHandler(UIBackgroundFetchResult.NewData)
}
Run Code Online (Sandbox Code Playgroud)
我在xcode控制台中收到的警告就是这个
Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.
Run Code Online (Sandbox Code Playgroud)
我不确定我是否在这里实现了正确的语法
我一直在努力装配一个UIImageView显示可变宽度和高度的图像Aspect Fill.单元格高度不适应新的高度UIImageView并保持其高度.
视图的层次结构就是这样
我在XCode自动布局中尝试了这些场景:
UIImageView => Height为remove at build timeIntrinsic Value的UIImageView到placeholderIntrinsic Value为每一个UIImageView,ContentView并UITableViewCell给placeholder有了这些组合中的任何一个,我得到了这个观
http://i.stack.imgur.com/Cw7hS.png
蓝线代表单元格边界(边界),绿色代表UIImageView边框(边界).在这个例子中有四个单元格,第一个和第三个单元格没有图像,第二个和第四个单元格具有相同的图像(溢出没有图像的图像).
我已经坚持了几天.我一直试图在回电中获取图像,但我总是得到nil.这些是我使用的选项:
let options = PHImageRequestOptions()
options.deliveryMode = .HighQualityFormat
options.resizeMode = .None
Run Code Online (Sandbox Code Playgroud)
我也尝试过nil没有运气的选项.这是我在传递给块的信息值中获得的数据.
[PHImageResultIsInCloudKey: 0,
PHImageResultDeliveredImageFormatKey: 9999,
PHImageFileURLKey: file:///var/mobile/Media/DCIM/100APPLE/IMG_0052.JPG,
PHImageResultRequestIDKey: 84,
PHImageResultIsDegradedKey: 0,
PHImageResultWantedImageFormatKey: 9999,
PHImageResultIsPlaceholderKey: 0,
PHImageFileSandboxExtensionTokenKey:
64b47b046511a340c57aa1e3e6e07994c1a13853;00000000;00000000;0000001a;com.apple.app-sandbox.read;;00000000;00000000;0000000000000000;/private/var/mobile/Media/DCIM/100APPLE/IMG_0051.JPG]
Run Code Online (Sandbox Code Playgroud)
我也试过用requestImageForAsset,得到了同样的结果.我想通过使用requestImageDataForAsset我将获得更多的数据控制.
此外,我认为该文件存在于云中,但它不是PHImageResultIsInCloudKey设置值0; 否则,我会下载它.
顺便说一句,我能够200x200在另一个视图中获得预定义大小的图像的较小版本; 然而,当我试图获得它的更大版本时,我得到零.我知道手机上的图像存在更高的分辨率(我可以在照片应用中看到它)
任何帮助将不胜感激.
我花了两个小时试图让这个简单的代码工作,没有运气.
我做了什么:
UImage(named: "resource.jpg")这不是一个重复的问题,因为Playground设置经历了6.3.1中的重大更改
然而,没有任何东西出现.这是我的屏幕快照.正如您所看到的,没有游乐场指示器在运行.

我一直在研究如何在资产目录中实现可调整大小的图像的不同技术,但是没有关于如何在Swift中为这些可调整大小的图像添加文本的例子(即使在Apple自己的指南中)并且允许它们动态调整大小.
如果有人知道如何做到这一点,知道链接到博客解释,这将是有帮助的.
我昨天发生了这个问题.我正在处理一段生产代码,这些代码在崩溃信息的某个时刻崩溃了
0 Goga 0x00000001000b90b8 function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Owned To Guaranteed> of Goga.NewViewController.emailButtonPressed (Goga.NewViewController)(ObjectiveC.UIButton) -> () (NewViewController.swift:0)
1 Goga 0x00000001000c0488 Goga.NewViewController.(emailButtonPressed (Goga.NewViewController) -> (ObjectiveC.UIButton) -> ()).(closure #2) (NewViewController.swift:872)
2 Goga 0x00000001000bd250 partial apply forwarder for reabstraction thunk helper from @callee_owned (@in ObjectiveC.UIAlertAction!) -> (@out ()) to @callee_owned (@owned ObjectiveC.UIAlertAction!) -> (@unowned ()) (NewViewController.swift:0)
Run Code Online (Sandbox Code Playgroud)
但是,当我发现错误时,在尝试复制问题数小时后,在崩溃日志中找不到任何错误消息.该错误在XCode中显示为:
在展开Optional值时意外地发现了nil
我的问题是,如何捕获生产代码中的nil-optional错误?
编辑:
只是为原始问题添加一点透视,我在此示例代码中发现了问题:
let cell = tableView.cellForRowAtIndexPath(indexPath)
cell.textLabel.text = "Hello" // CRASH if the cell is not visible in …Run Code Online (Sandbox Code Playgroud)