我的应用程序有时会忘记响应者应该处理触摸事件的内容.
我的情况:
UIButton,配置为将myAction:选择器发送FirstResponder到检测到"Touch Up Inside"事件时myAction:99%的时间,一切都很顺利.当用户点击按钮时,SubviewA负责处理该myAction:消息,一切都很好.但是,从时间到时间,用户抱怨按钮"冻结"了,我实际上转载它自己几次没有能够找到一个明确的情况下做到这一点的需求.
我到目前为止的调查是:
myAction: 未在SubviewA上调用我正在谈论的代码是我正在尝试解决的一些遗留代码.有一个视图响应其子视图的事件听起来像一个奇怪的架构给我.到目前为止,我一直使用文件所有者来处理触摸事件,所以我指出响应者链是理解错误的理想选择.但我找不到原因!根据我的理解,由于按钮不知道如何处理消息并且没有附加视图控制器,它应该将其转发到其超级视图(ButtonA,它知道如何处理它)!
我的问题是:
编辑:我对如何修复错误有所了解:将按钮操作直接连接到SubviewA而不是在Interface Builder中使用FirstResponder.我发布这个问题的原因是试图理解为什么响应者链不时不工作.
我编写了一个Rake脚本,该脚本应该与Crontab一起自动运行.在命令行中输入时脚本运行正常,但无法在cron内正确运行.
该脚本如下所示:
#!/bin/sh
echo `date`
cd /home/mick/myapp/current
rake RAILS_ENV=production mynamespace:myaction
Run Code Online (Sandbox Code Playgroud)
crontab设置如下所示:
10 0,6,12,18 * * * /home/mick/work/launch.sh >> /home/mick/work/launch.log
Run Code Online (Sandbox Code Playgroud)
执行后,日志文件只包含日期,但没有其他内容,我在syslog中得到的错误如下所示:
Mar 18 18:10:01 CRON[21773]: (mick) CMD (/home/mick/work/launch.sh >> /home/mick/work/launch.log)
Mar 18 18:10:01 CRON[21772]: (CRON) error (grandchild #21773 failed with exit status 127)
Mar 18 18:10:01 postfix/sendmail[21776]: fatal: open /etc/postfix/main.cf: No such file or directory
Mar 18 18:10:01 CRON[21772]: (mick) MAIL (mailed 1 byte of output; but got status 0x004b, #012)
Run Code Online (Sandbox Code Playgroud)
编辑:
感谢@Holger Just的评论,我发现这个链接帮助我得到了一个有效的脚本.
这是我的脚本的更新版本
#!/usr/bin/env bash # …Run Code Online (Sandbox Code Playgroud) 我的一个模型对象有一个枚举属性.为了将它存储在CoreData中,我使用了一个NSNumber对象.
不过,我想以方便的方式将其作为枚举类型访问.实现这一目标的最佳做法是什么?
到目前为止,我已经使用了以下代码.
在MyObject.h中
typedef enum _ABType {
ABTypeUnknown,
ABTypeValue1,
...
ABTypeValueN
} ABType;
@interface MyObject : NSManagedObject
@property (nonatomic, retain) NSNumber * myPersistentEnum; // Defined in my Core Data model
@property (nonatomic) ABType myConvenientEnum;
Run Code Online (Sandbox Code Playgroud)
在MyObject.m中
@dynamic myPersistentEnum;
- (BOOL)isValidEnumValue {
if (self.myPersistentEnum) {
int intValue = [self.type intValue];
if (intValue >= ABTypeValue1 && intValue <= ABTypeValueN) {
return YES;
}
}
ELog(@"Undefined enumValue %@", self.myPersistentEnum);
return NO;
}
- (ABType)myConvenientEnum {
if ([self isValidEnumValue]) {
return [self.type intValue];
} …Run Code Online (Sandbox Code Playgroud) 在尝试建立可互操作的加密系统时,我在轻松的"概念验证"期间遇到了一种奇怪的情况.
我在Ruby中编写了以下代码:
这是代码:
require 'openssl'
require 'base64'
# Read the dummy file
data = File.read("test.txt")
# Create an encrypter
cipher = OpenSSL::Cipher::AES.new(256, :CBC)
cipher.encrypt
key = "somethingreallyreallycomplicated"
cipher.key = key
# Encrypt and save to a file
encrypted = cipher.update(data) + cipher.final
open "encrypted.txt", "w" do |io| io.write Base64.encode64(encrypted) end
# Create a decrypter
decipher = OpenSSL::Cipher::AES.new(256, :CBC)
decipher.decrypt
decipher.key = key
# Decrypt and save to a file
encrypted_data = Base64.decode64(File.read("encrypted.txt"))
plain = decipher.update(encrypted_data) + decipher.final …Run Code Online (Sandbox Code Playgroud) 我开始使用 ReactiveCocoa,但仍然在一些基本概念上苦苦挣扎:
init在我的视图模型中)didFindCurrentPosition被调用)viewDidLoad在我的视图控制器中)viewDidLoad)我的问题是:完成步骤 2 后,如果信号上没有发送其他事件,我的视图控制器不会收到通知。
我的视图控制器如何访问信号的最后一个值?(即如何在步骤 3 中访问步骤 2 中发出的值?)
感谢您的帮助。
PS:ReactiveCocoa 看起来像一个很棒的库,但我对文档的状态感到困惑。恕我直言,它不是很清楚,并且缺乏一些关于如何使用它的明确指南。
视图模型:
class MyViewModel: LocationManagerDelegate {
let locationManager: LocationManager
let geolocationDataProperty = MutableProperty<Geolocation?>(nil)
let geolocationData: Signal<Geolocation?, NoError>
init() {
geolocationData = geolocationDataProperty.signal
// Location Management
locationManager = LocationManager()
locationManager.delegate = self
locationManager.requestLocation()
}
// MARK: - LocationManagerDelegate
func didFindCurrentPosition(location: CLLocation) {
geolocationDataProperty.value = Geolocation(location: location)
}
}
Run Code Online (Sandbox Code Playgroud)
视图控制器:
class MyViewController: UIViewController {
let viewModel = …Run Code Online (Sandbox Code Playgroud) reactive-programming ios reactive-cocoa swift reactive-cocoa-5
我打开了一个iOS项目 - 使用Xcode 4.4.1 - 我没有打开2个月(即使用Xcode 4.3).首先,Xcode在显示项目导航器之后不断崩溃,说"无法关联工作树".
我试图通过删除xcuserdata文件和project.xcworkspace目录来修复它.
现在,Xcode打开而不会崩溃,但在方案视图中,它显示为Mac OS X项目,而项目和目标都正确设置为"最新iOS"基础SDK.
如何在不重新创建项目并复制所有源文件的情况下解决这个问题?
编辑:我正在使用Git与GitHub遥控器.
我无法使用私人cocoapods回购中的吊舱.
当我尝试使用版本0.37.1添加我的pod时,出现以下错误:
[!] Unable to find a specification for ...
Run Code Online (Sandbox Code Playgroud)
我的cocoapods配置使用2个遥控器:
$ pod repo list
bootstragram-public-pod-repo
- Type: git (master)
- URL: https://github.com/Bootstragram/bootstragram-public-pod-repo.git
- Path: /Users/mick/.cocoapods/repos/bootstragram-public-pod-repo
master
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/mick/.cocoapods/repos/master
2 repos
Run Code Online (Sandbox Code Playgroud)
当我使用时pod install --verbose,似乎只master检查了回购,而不是私有回购:
Preparing
Migrating to CocoaPods 0.36
Analyzing dependencies
Updating spec repositories
Updating spec repo `master`
...
Inspecting targets to integrate
Using `ARCHS` setting to build architectures of target `Pods`: (``)
...
Resolving dependencies of `Podfile` …Run Code Online (Sandbox Code Playgroud) 现在,iOS Firebase SDK是开源的,我想使用Firebase作为依赖项来构建pod。为此,我使用以下内容创建了一个新的pod模板。
我的问题是我可以从示例项目中导入FirebaseDev,但不能从开发窗格中导入。我知道在SDK开源之前这是一个问题,但我希望现在能够解决此问题,但是我需要帮助确定问题所在。有人可以帮忙吗?
.podspec:s.dependency 'FirebaseDev'
s.dependency 'FirebaseDev/Core'
s.dependency 'FirebaseDev/Auth'
s.dependency 'FirebaseDev/Database'
Run Code Online (Sandbox Code Playgroud)
Example/Podfile:pod 'FirebaseDev', :git => 'https://github.com/firebase/firebase-ios-sdk'
pod 'FirebaseDev/Core', :git => 'https://github.com/firebase/firebase-ios-sdk'
pod 'FirebaseDev/Auth', :git => 'https://github.com/firebase/firebase-ios-sdk'
pod 'FirebaseDev/Database', :git => 'https://github.com/firebase/firebase-ios-sdk'
Run Code Online (Sandbox Code Playgroud) 有没有办法将某些Swift函数标记为实现某些协议函数,以便在协议的签名发生更改时,编译器可以将实现标记为错误.
例如,考虑这个例子,我有一个实例Foo协议的默认实现UIViewController,我想覆盖它作为Bar子类的自定义类UIViewController.
// V1
protocol Foo {
func number() -> Int
}
extension Foo where Self: UIViewController {
func number() -> Int {
return 0
}
}
// Overrides the default implementation
extension Bar: Foo {
func number() -> Int {
return 1
}
}
Run Code Online (Sandbox Code Playgroud)
现在,该协议演变为:
// V2
protocol Foo {
func numberV2() -> Int
}
extension Foo where Self: UIViewController {
func numberV2() -> Int {
return 0
}
}
// …Run Code Online (Sandbox Code Playgroud) 将ReactiveSwift转换为最优雅的方式SignalProducer<A, NetworkError>是Signal<A, NoError>什么?
大多数时候,我的信号生成器是网络调用的结果,所以我想将结果分成两种情况:
Signal<A, NoError>Signal<String, NoError>带有错误的本地化描述的a(为什么?因为我想尽可能成为MVVM)
到目前为止,我最终写了很多样板文,如下所示:
let resultsProperty = MutableProperty<SearchResults?>(nil)
let alertMessageProperty = MutableProperty<String?>(nil)
let results = resultsProperty.signal // `Signal<SearchResults?, NoError>`
let alertMessage = alertMessageProperty.signal // `Signal<String?, NoError>`
// ...
searchStrings.flatMap(.latest) { string -> SignalProducer<SearchResults, NetworkError> in
return MyService.search(string)
}
.observe { event in
switch event {
case let .value(results):
resultsProperty.value = results
case let .failed(error):
alertMessageProperty.value = error
case .completed, .interrupted:
break
}
}
Run Code Online (Sandbox Code Playgroud)
即:
是否有预处理器指令使XCode构建失败?(或pragma_mark或其他)
例如,我为3种不同的环境开发了一个应用程序,包括几个要获取的Web URL.到目前为止,我不知道将用于生产环境的URL,我想在我的代码中插入一条指令,以防止预期的构建与此环境一起运行.
我的代码看起来像
#ifdef ENV1
...
#endif
#ifdef ENV2
...
#endif
#ifdef ENV3
#some_instruction_that_prevent_success_build
...
#endif
Run Code Online (Sandbox Code Playgroud)
换句话说,我想要一个充当阻塞TODO的指令.
今天,每当我开始delayed_job工作时,这个过程都会立即死而且无声无息.
经过一些调查(并找出前景模式delayed_job),我终于发现问题是delayed_job序列化我的活动记录对象在YAML加载部分触发异常的方式:
Psych::SyntaxError: (<unknown>): mapping keys are not allowed in this context at line 7 column 14
from /Users/mick/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych.rb:203:in `parse'
from /Users/mick/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych.rb:203:in `parse_stream'
from /Users/mick/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych.rb:151:in `parse'
from /Users/mick/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych.rb:127:in `load'
from /Users/mick/.rvm/gems/ruby-1.9.3-p448/gems/safe_yaml-0.9.7/lib/safe_yaml.rb:144:in `load_with_options'
from (irb):111
from /Users/mick/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.16/lib/rails/commands/console.rb:47:in `start'
from /Users/mick/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.16/lib/rails/commands/console.rb:8:in `start'
from /Users/mick/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.16/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Run Code Online (Sandbox Code Playgroud)
delayed_job尝试时发生了什么:
YAML.load(my_job.handler)
Run Code Online (Sandbox Code Playgroud)
找到有问题的Delayed::Backend::ActiveRecord::Job实例后,puts my_job.handler会显示:
object: !ruby/ActiveRecord:MyActiveRecord
attributes:
id: 7648
... some good stuff ...
my_field: ? …Run Code Online (Sandbox Code Playgroud) 我在Mac OS X Lion环境中使用RVM安装了Ruby和Rails.
我使用mysql2 gem(使用MAMP库而不是mysql安装)使Rails正常工作.一切都很好......
直到我尝试编写一个独立的ruby脚本(在Rails上下文中).而现在我无法让mysql2 gem工作.
从脚本内部或Ruby命令行(irb),
require "mysql2"
Run Code Online (Sandbox Code Playgroud)
指令导致以下错误:
1.9.2p290 :001 > require "mysql2"
dyld: lazy symbol binding failed: Symbol not found: _mysql_get_client_info
Referenced from: /Users/mick/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
Expected in: flat namespace
dyld: Symbol not found: _mysql_get_client_info
Referenced from: /Users/mick/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
Expected in: flat namespace
Run Code Online (Sandbox Code Playgroud)
我尝试过几种东西:
export DYLD_LIBRARY_PATH=/Applications/MAMP/Library/lib/mysql/:$DYLD_LIBRARY_PATH
运用 sudo ln -s /Applications/MAMP/Library/lib/mysql/libmysqlclient.16.dylib /usr/lib/libmysqlclient.16.dylib
没有任何效果.我想我很快就会哭...