我正在尝试构建一个像闹钟一样工作的iPhone应用程序,我正在使用UILocalNotification
问题
替代方法
是否可以使用自定义振动模式?(http://www.pcworld.com/article/242238/how_to_use_custom_vibrations_in_ios_5.html)
当推送通知被触发时,是否可以执行方法?(但应用程序可能甚至没有运行,但它需要工作)
NSTimer是一个选择吗?(但应用程序可能甚至没有运行,但它需要工作)
还有其他替代品吗?
Apple仍然接受使用Xcode 7.3.1
(Swift 2.2
)为AppStore构建的应用程序吗?
还是必须迁移到Xcode 8
(至少Swift 2.3
或以上)?
注意:请参阅预期输出与实际输出
#import<Foundation/Foundation.h>
int main()
{
system("clear");
NSDictionary *d1 = nil;
@autoreleasepool
{
d1 = [[NSDictionary alloc] initWithObjectsAndKeys: @"AAA", [NSNumber numberWithInt:10],
@"BBB", [NSNumber numberWithInt:20],
@"CCC", [NSNumber numberWithInt:30],
nil];
}
for(NSNumber* n1 in d1) //I expected fast enumeration for NSDictionary to be based on the
//ascending order of the key but that doesn't seem to be the case
{
printf("key = %p"
"\t [key intValue] = %i"
"\t value = %s\n", …
Run Code Online (Sandbox Code Playgroud) 有没有办法将属性作为参数传递给函数?
class Car {
let doors : Int = 4
let price : Int = 1000
}
Run Code Online (Sandbox Code Playgroud)
有没有办法将Car属性作为类型传递给函数?
我想实现以下目标:
func f1(car: Car, property: SomeType) {
println(car.property)
}
let c1 = Car()
f1(c1, doors)
f1(c1, price)
Run Code Online (Sandbox Code Playgroud)
将关闭帮助,如果又如何?
有2 URLRequest
s,一个有httpBody
,没有一个httpBody
。
但是,进行比较时,表明两者相等。
这是预期的行为还是我缺少了什么?
let url = URL(string: "www.somevalidURL.com")!
var r1 = URLRequest(url: url)
r1.addValue("Content-Type", forHTTPHeaderField: "application/json; charset=utf-8")
r1.httpBody = makeBody(withParameters: ["email" : "a@b.com"])
var r2 = URLRequest(url: url)
r2.addValue("Content-Type", forHTTPHeaderField: "application/json; charset=utf-8")
if r1 == r2 {
print("requests are equal")
}
else {
print("requests are not equal")
}
if r1.httpBody == r2.httpBody {
print("body is equal")
}
else {
print("body is not equal")
}
func makeBody(withParameters bodyParameters: [String : Any]?) -> …
Run Code Online (Sandbox Code Playgroud) 我有一个包含以下结构的工作区:
工作空间:
-- SomeApp
-- SomeFramework
---- DataService.swift
---- FrameworkModel.xcdatamodeld
Run Code Online (Sandbox Code Playgroud)
SomeFramework 已添加(嵌入并签名)到 SomeProject。
persistentContainer.viewContext
SomeFramework
import Foundation
import CoreData
public class DataService {
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "FrameworkModel")
container.loadPersistentStores { description, error in
if let error = error {
fatalError("Unable to load persistent stores: \(error)")
}
}
return container
}()
public init() {
print(persistentContainer.viewContext) //Crashes here because "Failed to load model named …
Run Code Online (Sandbox Code Playgroud) 概述:
我有一个iOS项目,其中包括:
NSFetchedResultsController
)UITableView
)我想做的事:
我做了什么
NSFetchedResultsControllerDelegate
方法内部,lastAddedIndexPath
当类型为insert/update/move时,我将索引路径存储在属性中代码(NSFetchedResultsControllerDelegate)
- (void)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
if (!self.suspendAutomaticTrackingOfChangesInManagedObjectContext)
{
switch(type)
{
case NSFetchedResultsChangeInsert:
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
NSLog(@"going to store insert - scroll");
self.lastAddedIndexPath = newIndexPath;
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
NSLog(@"going to store update - scroll");
self.lastAddedIndexPath = newIndexPath;
break;
case NSFetchedResultsChangeMove:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths:[NSArray …
Run Code Online (Sandbox Code Playgroud) 概观
UILocalNotification
repeatInterval
设置为NSWeekdayCalendarUnit
我想做的事
repeatInterval
重复,题
repeatInterval
为了不重复,我应该设定的常数是多少?SomeOperation went isFinished=YES without being started by the queue it is in
public class SomeOperation : AsyncOperation {
//MARK: Start
public override func start() {
isExecuting = true
guard !isCancelled else {
markAsCompleted() //isExecuting = false, isFinished = true
return
}
doSomethingAsynchronously { [weak self] in
self?.markAsCompleted() //isExecuting = false, isFinished = true
}
}
//MARK: Cancel
public override func cancel() {
super.cancel()
markAsCompleted() //isExecuting = false, isFinished = true …
Run Code Online (Sandbox Code Playgroud) 概观
题
接下来的步骤
输出注意到了
setBeforeSave.count = 1
setAfterSave.count = 0
Run Code Online (Sandbox Code Playgroud)
NSManagedObjectContext
方法insertedObjects
返回1个对象NSManagedObjectContext
方法insertedObjects
返回0个对象NSManagedObjectContext
方法save:
返回YES
.插入对象的代码
Test *test = [NSEntityDescription insertNewObjectForEntityForName:@"Test" inManagedObjectContext:self.database.managedObjectContext];
Run Code Online (Sandbox Code Playgroud)
保存代码:
//database is a property of the type UIManagedDocument
NSSet *setBeforeSave = [self.database.managedObjectContext insertedObjects];
NSLog(@"setBeforeSave.count = %i", setBeforeSave.count);
NSError *error = nil;
if(![self.database.managedObjectContext save:&error])
NSLog(@"error = %@", error);
NSSet *setAfterSave = [self.database.managedObjectContext insertedObjects]; …
Run Code Online (Sandbox Code Playgroud) 概述:
斯坦福iOS教程包含一个实现(标题+实现文件),以帮助在使用核心数据时使用表视图.
链接 - http://www.stanford.edu/class/cs193p/cgi-bin/drupal/downloads-2011-fall
文件名 - CoreDataTableViewController.zip(包含下面提到的2个文件)
它在两个文件中都包含以下文本:
// CoreDataTableViewController.h
//
// Created for Stanford CS193p Fall 2011.
// Copyright 2011 Stanford University. All rights reserved.
Run Code Online (Sandbox Code Playgroud)
题
如何制作NSTextView
可滚动的?
class ViewController: NSViewController {
private let textView = NSTextView()
//MARK: Manage Views
override func viewDidLoad() {
super.viewDidLoad()
setupTextView()
}
private func setupTextView() {
textView.isEditable = false
view.addSubview(textView)
textView.translatesAutoresizingMaskIntoConstraints = false
textView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
textView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
textView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
textView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
}
}
Run Code Online (Sandbox Code Playgroud) 我想为iOS应用程序构建一个设置界面.
注意 - 这些设置通常会更改,所以我更喜欢设置界面应用程序而不是设置包
我的想法
问题:
在模态视图中,似乎没有出现导航栏.我需要导航栏,以便我可以在其上创建一个"保存"按钮?
为了解决上面提到的问题,我创建了一个UIViewController来管理设置视图,并在UIViewController的视图下添加了一个导航栏和一个表视图(使用UITableViewController使导航栏与单元格一起滚动)
但是创建一个UIViewController不允许我创建一个包含静态内容的表
问题:
ios ×9
swift ×6
core-data ×4
uitableview ×2
closures ×1
cocoa ×1
licensing ×1
macos ×1
nsdictionary ×1
nsoperation ×1
nstextview ×1
objective-c ×1
segue ×1
swift4.2 ×1
urlrequest ×1
xcode ×1