关闭ARC:
我使用创建自定义类的实例alloc,因此它的保留计数为1.
在下一行,我NSLog()实例(我description在我的自定义类中实现了一个方法).
在下一行,我释放了该对象.
在下一行,我再次NSLog()实例,即我发送description消息,我在控制台中看到相同的输出.我期待某种错误输出.
这是相关代码:
AppDelegate.m:
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
Greeter* host = [[Greeter alloc] initWithName:@"Maggie"]; //My custom class
NSLog(@"Greeter %@", host);
[host release];
NSLog(@"Greeter %@", host); //Create error: send a `description` message to an object whose retain count is 0.
return YES;
}
...
...
Run Code Online (Sandbox Code Playgroud)
Greeter.m:
...
- (NSString*)description {
return [
[[NSString alloc] initWithFormat:@"\n\tname: %@ \n\tCreated on %@", [self …Run Code Online (Sandbox Code Playgroud) 是否有滚动条允许在Xcode 6中的Assistant Editor预览中进行水平/垂直滚动?
我知道你可以放大和缩小,但缩小时你一次只能看到一个设备.
我正在尝试搜索从JSON获得的字典数组中的值.我有一个tableViewController带UISearchResultsUpdating.我找到了一个包含字符串数组的示例:
func updateSearchResultsForSearchController(searchController: UISearchController)
{
filteredTableData.removeAll(keepCapacity: false)
let searchPredicate = NSPredicate(format: "SELF contains[c] %@", searchController.searchBar.text)
let array = tableData.filteredArrayUsingPredicate(searchPredicate)
filteredTableData = array as! [String]
self.tableView.reloadData()
}
Run Code Online (Sandbox Code Playgroud)
我真的不知道如何在数组中进行搜索:
(
{
id = 3;
name = TestNewYork;
},
{
id = 2;
name = TestLA;
},
{
id = 1;
name = TestWashington;
}
)
Run Code Online (Sandbox Code Playgroud)
我tableData = []也filteredTableData必须是一个阵列
请帮忙!
我正在努力完成的任务:
var mapNames = [String]()
var mapLocation = [String]()
for valueMap in valueMaps {
if let name = valueMap.name {
mapNames.append(name)
}
if let location = valueMap.location {
mapLocation.append(location)
}
}
Run Code Online (Sandbox Code Playgroud)
使用高阶函数或数组方法(array.filter等)来压缩上面的代码并避免使用for循环的最佳方法是什么
这是我尝试过的,但编译器给出了一个错误:
let getArrayOfNames = valueMaps.filter() {
if let name = ($0 as valueMaps).name as [String]! {
return name;
}
}
let getArrayOfLocations = valueMaps.filter() {
if let type = ($0 as valueMaps).location as [String]! {
return type;
}
}
Run Code Online (Sandbox Code Playgroud) iOS 8.我将呈现一个具有演示风格的视图控制器:UIModalPresentationOverCurrentContext.这很有效,直到我旋转我的设备,此时显示的视图没有正确调整.
示例:我介绍了一个肖像上下文.我的新视图覆盖整个屏幕(具有半透明度).我转向风景.呈现的视图旋转,但现在居中并保持纵向宽度.
呈现VC和呈现视图都是使用自动布局在故事板中创建的.因为我不能在VC的最顶层视图中添加约束(对吗?)我不知道如何保持我的呈现视图完全覆盖它下面的视图.
我正在为我的应用程序实现iOS Share Extension,并且我希望能够将任何类型的文件添加到我的应用程序扩展中(例如,从Dropbox共享的任何类型的二进制文件)。
我该如何实现这种行为?loadItemForTypeIdentifier:options:completionHandler:期望使用UTI,我尝试提供一个空字符串,但是没有用。
我有以下崩溃报告.它只发生在iOS 8上.我确切知道如何重现它,但不能在我的生活中找出问题在我的代码中的位置.当我使用断点并尝试单步执行应用程序时,崩溃不会发生.如何在我的应用中找到问题所在?
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0x10
Crashed Thread: 0
Application Specific Information:
objc_msgSend() selector name: respondsToSelector:
Thread 0 Crashed:
0 libobjc.A.dylib 0x00000001974b3bd0 objc_msgSend + 16
1 UIKit 0x000000018ab960f4 -[UIToolbar _didMoveFromWindow:toWindow:] + 108
2 UIKit 0x000000018aa30d44 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 700
3 UIKit 0x000000018aa30d44 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 700
4 UIKit 0x000000018aa30d44 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 700
5 UIKit 0x000000018aa303dc __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 140
6 UIKit 0x000000018aa302bc -[UIView(Hierarchy) _postMovedFromSuperview:] + 480
7 UIKit 0x000000018aa3c0b0 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1788
8 UIKit …Run Code Online (Sandbox Code Playgroud) 我目前有一个测试应用程序来自学Core Location.这是一个带有按钮的应用程序,可以在按下按钮时显示您的位置,也可以在位置服务关闭时显示警报.
我得到一个致命的错误(在解包选项值时意外地发现nil)当位置服务打开并且我尝试打印字符串时.我在文档中找不到CLLocationManager.location.coordinate返回可选值的任何地方.我将包含代码段.谢谢!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
if CLLocationManager.authorizationStatus() == .NotDetermined {
locationManager.requestWhenInUseAuthorization()
}
}
@IBAction func testLocation(sender: AnyObject) {
switch CLLocationManager.authorizationStatus() {
case .AuthorizedAlways, .AuthorizedWhenInUse:
printCurrentCoordinates()
case .Restricted, .Denied:
disabledLocationSeriveAlert()
default:
println("Failed")
}
func printCurrentCoordinates() {
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
println("\(locationManager.location.coordinate.latitude)")
println("\(locationManager.location.coordinate.longitude)")
}
func disabledLocationSeriveAlert() {
let alert = UIAlertController(title: "Unable to retrieve location", message: "Enable location services in system settings", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil) …Run Code Online (Sandbox Code Playgroud) 在我的项目中,我需要使用一些tableView单元可扩展且其中一些是独立的来实现UITableview。如果是可扩展单元格,则需要指示“ +”符号。在此处输入图片描述。有人可以帮帮我吗
我有各种时间间隔的图像.一个例子是"1.5d-4h.png",也就是4小时到1.5天之间.我为每个区间图像定期提供@ 2x和@ 3x资源,并且我确保它们都是PNG(不是JPG),但由于某些原因,某些间隔图像无法imageNamed仅通过iOS 7加载.iOS 8设备正确加载所有可能的间隔图像.
从一些进一步的测试看起来像在iOS 7上,如果你完全符合名称,imageNamed它就能成功地使用所有这些图像,例如
(lldb) po [UIImage imageNamed:@"1.5d-4h.png"]
<UIImage: 0x7ec390>
(lldb) po [UIImage imageNamed:@"1.5d-4h"]
nil
Run Code Online (Sandbox Code Playgroud)
在iOS 7和8上成功加载的图像示例:
(lldb) po [UIImage imageNamed:@"10-9d"]
<UIImage: 0x10cc290>
Run Code Online (Sandbox Code Playgroud)
这是完整的时间间隔:
@"4h-0min"
@"1.5d-4h" // fails
@"4.5-1.5d" // fails
@"5.5-4.5d" // fails
@"7-5.5d" // fails
@"9-7d"
@"10-9d"
Run Code Online (Sandbox Code Playgroud)
有什么建议?