我对这个问题感到非常愚蠢,但文档和谷歌都没有给我任何爱.
我有一个Unicode字符,我想插入我的iPhone应用程序的源代码中的字符串文字.我知道它的十六进制值.什么是适当的转义序列?就此而言,我忽略了哪些明显的信息来源会告诉我这个?
我正在为我的一个应用程序创建一个自动布局友好的拆分视图类.它的各种功能之一是它可以折叠窗格,并且可以动画它们的崩溃,就像你可能已经看过NSSplitView那样.
由于我正在使用约束,我通过在窗格上放置一个必需的width =(当前宽度)约束,然后以动画方式将约束的常量设置为0来实现此目的:
- (NSLayoutConstraint*)newHiddenConstraintAnimated:(BOOL)animated {
NSLayoutConstraint * constraint = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:NSWidth(self.view.frame)];
constraint.priority = NSLayoutPriorityRequired;
CABasicAnimation * anim = [CABasicAnimation animation];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
anim.duration = 0.2;
constraint.animations = [NSDictionary dictionaryWithObject:anim forKey:@"constant"];
[self.view addConstraint:constraint];
[(animated ? constraint.animator : constraint) setConstant:0.0];
return constraint;
}
Run Code Online (Sandbox Code Playgroud)
这很好用.不幸的是,稍后扩展窗格并不是很好.
- (void)removeHiddenConstraintAnimated:(BOOL)animated {
if(!animated) {
[self.view removeConstraint:self.hiddenConstraint];
}
else {
NSLayoutConstraint * constraint = self.hiddenConstraint;
NSView * theView = self.view;
[NSAnimationContext beginGrouping];
[constraint.animator setConstant:self.width];
[NSAnimationContext currentContext].completionHandler = ^{
[theView …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个基于故事板的iPhone应用程序并正在进行状态恢复.当正常执行segues时,我希望让它们具有动画效果,但是当我恢复导航层次结构的几个级别时,我只想让最后一个segue动画化.除了设置两组segue之外 - 一组使用普通push segue,另一组使用自定义非动画push segue - 有没有办法实现我想要做的事情?
我正在创建一个视图控制器,它使用在导航栏和状态栏后面滑动的Web视图.为此,我将该webView.scrollView.contentInset
属性设置为具有顶部插入64
.
但是,这不会缩小Web视图要占用的区域数量,因此如果页面小于屏幕,则底部有64 px的空白区域可以滚动.Web视图是垂直的UIPageViewController
,因此这会中断分页.有没有办法摆脱这个额外的空间?
假设用户想要取消他们的订阅,所以我发出如下命令:
stripe_subscription.delete(at_period_end: true)
Run Code Online (Sandbox Code Playgroud)
但是,在此期间结束之前,用户会改变主意.是否有我可以发出撤消预定取消的电话?
如果没有,实现这个的最佳方法是什么?我最好的猜测是这样的:
new_subscription = stripe_customer.subscriptions.create(plan: stripe_subscription.plan.id, trial_end: stripe_subscription.current_period_end)
stripe_subscription.delete() # if permitted
self.stripe_subscription = new_subscription
save!
Run Code Online (Sandbox Code Playgroud)
我能做些什么吗?
好的,Apple给我们带来了ARC,这很棒.在将我的应用程序重构为ARC之后,几乎所有工作都正常,现在开发和维护起来要容易得多.
只有一个问题我仍然无法弄清楚.
我的工作管理程序在自己的窗口中显示提案,订单等的不同详细信息.所以我有一个特殊的类,其中WindowControllers被分配并使用initWithWindowNibName启动,然后窗口显示为showWindow:
DetailWindowController *proposalWindowController = [[DetailWindowController alloc] initWithWindowNibName:@"ThePorposalWindow"];
[proposalWindowController showWindow:nil];
Run Code Online (Sandbox Code Playgroud)
在ARC之前,WindowController的实例执行了如文档中所示的发布:
- (void)windowWillClose:(NSNotification *)notification
{
[self autorelease];
}
Run Code Online (Sandbox Code Playgroud)
但是现在使用ARC这是不可能的,更糟糕的是,在我分配和启动WindowController的特殊类中,ARC释放了相同的windowController,因为没有指向windowController的指针.
我的想法是将windowController复制到一个可变数组中:
[proposalWindowArray addObject:proposalWindowController];
[[proposalWindowArray lastObject] showWindow:nil];
Run Code Online (Sandbox Code Playgroud)
并在windowControllers委托方法windowWillClose中我向我的特殊类发布通知:
- (void)windowWillClose:(NSNotification *)notification
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"ProposalWindowWillClose" object:[[self window] windowController] userInfo:nil];
}
Run Code Online (Sandbox Code Playgroud)
在我的特殊类中,我听取通知并从数组中删除对象:
- (void) proposalWindowWasClosed: (NSNotification *) notification
{
[proposalWindowArray removeObjectIdenticalTo:[notification object]];
}
Run Code Online (Sandbox Code Playgroud)
它有效,但我仍然不相信这是正确的方法.
有没有人有同样的问题或提示让它变得更好?
macos cocoa design-patterns memory-management automatic-ref-counting
他们是一种编码/解码HTML和URL的方法(在Xcode中,使用Objective-C)?
[NSString stringWithContentsOfFile:<#(NSString *)path#> encoding:<#(NSStringEncoding)enc#> error:<#(NSError **)error#>]
Run Code Online (Sandbox Code Playgroud)
这似乎不符合我的预期.我认为它会将像"<"这样的特殊字符转换为等效的HTML实体,在这种情况下是"<".
以下是与该主题相关的w3school链接的参考(一般):
感谢期待.
我正在研究基于Perl的文件同步工具.它将文件下载到临时目录(保证与真实文件位于同一文件系统上),然后将临时文件移动到旧文件系统上,保留权限,所有权和ACL等元数据.我想知道如何在Linux上实现最后一步.
在Mac OS X上,至少在C中,我会使用该exchangedata
功能.这需要两个文件名作为参数并交换其内容,使所有元数据(除了mtime)保持不变.它保证操作是原子的 - 所有读者都会看到旧文件或新文件,从不介于两者之间.不幸的是,我不认为它可以在Linux上使用.
我知道它rename
会以原子方式移动,但它不会保留元数据.另一方面,我可以打开文件并使用新文件的内容覆盖数据,这将保留所有元数据,但不会是原子操作.有关解决这个问题的任何建议吗?
我有一个沙盒Cocoa应用程序,在导出过程中,需要运行第三方命令行工具.此工具似乎是硬编码/tmp
用于其临时文件; 沙盒不允许访问此文件夹,因此导出失败.
如何运行此工具?我无法访问其源代码,因此我无法修改它以使用NSTemporaryDirectory()
它,并且它似乎不尊重TMP
或TEMPDIR
环境变量.由于我不理解的原因,给自己一个com.apple.security.temporary-exception.files.absolute-path.read-write
权利似乎也没有用.
有没有办法在我的沙盒中重新映射文件夹?我可以使用一些不起眼的技巧吗?我应该尝试以某种方式修补工具的二进制文件吗?我在这里结束了我的智慧.
使用sqlite3进行本地开发.Prod DB是MySql.
有一个用于列更改的迁移文件.
class ChangeDateToOrders < ActiveRecord::Migration
def self.up
change_column(:orders, :closed_date, :datetime)
end
def self.down
change_column(:orders, :closed_date, :date)
end
end
Run Code Online (Sandbox Code Playgroud)
错误说出来 index name 'temp_index_altered_orders_on_closed_location_id_and_parent_company_id' on table 'altered_orders' is too long; the limit is 64 characters
知道sqlite对索引名称有限制,但有没有解决方法呢?
编辑我使用的解决方法.
class ChangeDateToOrders < ActiveRecord::Migration
def self.up
remove_index(:orders, [:closed_location_id, :parent_company_id])
change_column(:orders, :closed_date, :datetime)
add_index(:orders, [:closed_location_id, :parent_company_id], :name => "add_index_to_orders_cli_pci")
end
def self.down
remove_index(:orders, :name => "add_index_to_orders_cli_pci")
change_column(:orders, :closed_date, :date)
add_index(:orders, [:closed_location_id, :parent_company_id])
end
end
Run Code Online (Sandbox Code Playgroud) macos ×3
cocoa ×2
cocoa-touch ×2
iphone ×2
animation ×1
atomic ×1
autolayout ×1
c ×1
encoding ×1
escaping ×1
file ×1
ios ×1
linux ×1
nsstring ×1
objective-c ×1
perl ×1
segue ×1
uikit ×1
uiscrollview ×1
uistoryboard ×1
uiwebview ×1
unicode ×1
urlencode ×1