
Cocoa-Objective-C & Swift
文章平均质量分 52
sjcode
这个作者很懒,什么都没留下…
展开
-
取其它app安装路径
取其它app安装路径NSString* iTunesPath = [ [ NSWorkspace sharedWorkspace ] absolutePathForAppBundleWithIdentifier: @"com.apple.iTunes" ];if( iTunesPath ) { // iTunes installed, do something}原创 2012-03-09 14:29:40 · 681 阅读 · 0 评论 -
iOS8 adaptive segue
Here is a quick summary of the segues and an example for each type. You'll want to do more research/experimentation if you decide to implement them.Show - Pushes the destination view controller on转载 2015-08-26 22:51:30 · 947 阅读 · 0 评论 -
mantle的Array与dictionary
json格式:NSDictionary *dict = @{ @"name": @"Bob", @"cars": @[ @{ @"make":@"ford",原创 2015-09-02 18:27:25 · 1195 阅读 · 0 评论 -
Core animation 学习笔记
图层每一个UIView都有一个CALayer 改变UIView里Layer的frame,bounds,backgroundColor都会影响UIView添加到父图层的子图层,当只设置bounds时.position为 {0,0} anchorPoint为{0.5,0.5} 子图层的中心位置 CALayer *subLayer = [CALayerl原创 2015-09-11 11:08:47 · 433 阅读 · 0 评论 -
在mac下通过tcpdump抓iPhone包
rvictl -s 87b8622c5748dea98a982aa41026fbbb80dc892287b8622c5748dea98a982aa41026fbbb80dc8922 为udidlo0 gif0 stf0 en0 en1 en2 p2p0 awdl0 bridge0 utun0 en4 rvi0之后rvi0就是设备句柄,可以用tcp原创 2015-09-21 14:24:50 · 1746 阅读 · 0 评论 -
RAC笔记
//signal1,signal2有任何一个被订阅,即x等于一个RACTupleRACSignal*signal1 = [RACSignaldefer:^RACSignal*{ NSLog(@"aaaa"); return [RACSignalreturn:@"hello111"]; }];原创 2016-01-26 10:26:59 · 2289 阅读 · 0 评论 -
Detect volume change
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(systemVolumeChanged:)name:@"AVSystemController_SystemVolumeDidChangeNotification"object:nil];- (void)原创 2016-02-16 10:34:02 · 588 阅读 · 0 评论 -
在OSX下使用命令行修改IP与网关
sudeMacBook-Pro-3:~ sujian$ networksetup -listnetworkserviceorderAn asterisk (*) denotes that a network service is disabled.(1) Thunderbolt Ethernet(Hardware Port: Thunderbolt Ethernet, De原创 2016-03-29 13:34:46 · 4236 阅读 · 0 评论 -
Xcode 7.3 cannot create __weak reference in file using manual reference counting
Set Build Settings -> Apple LLVM 7.1 - Language - Objective C -> Weak References in Manual Retain Release to YES.参考:http://stackoverflow.com/questions/36147625/xcode-7-3-cannot-create-weak-ref原创 2016-03-30 15:03:58 · 6808 阅读 · 0 评论 -
通过Reactivecocoa绑定UISwitch到NSUserDefault
RACChannelTerminal *switchTerminal = self.someSwitch.rac_newOnChannel;RACChannelTerminal *defaultsTerminal = [[NSUserDefaults standardUserDefaults] rac_channelTerminalForKey:@"someBoolKey"];[switch转载 2016-03-31 12:33:51 · 1581 阅读 · 0 评论 -
Xcode升级后插件失效的原理与修复办法
find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add `defaults read /Applicati转载 2015-11-10 11:17:57 · 848 阅读 · 0 评论 -
Popup custom view on current view
很多时候需要在原视图上弹出一个自定义视图让用户确认一些东西. 通常的做法一般使用UIAlertView/UIAlertController. 但是做为自定义它们的风格可能与app不符.思路如下:1) 创建一个UIViewController,背景是一个UIImageView,Autolayout至全屏,图片选用半透明的,目标是为了显示前一页的部分内容2) 通过presentVi原创 2016-04-19 16:32:12 · 414 阅读 · 0 评论 -
到底什么时候才需要在ObjC的Block中使用weakSelf/strongSelf
到底什么时候才需要在ObjC的Block中使用weakSelf/strongSelf2014-11-22, SAT | COMMENTSObjective C 的 Block 是一个很实用的语法,特别是与GCD结合使用,可以很方便地实现并发、异步任务。但是,如果使用不当,Block 也会引起一些循环引用问题(retain cycle)—— Block 会 retain转载 2016-07-13 23:39:26 · 539 阅读 · 0 评论 -
Reactivecocoa-publish、multicast、replay、replayLast
//-replay 总是收取最后的内容,而并不执行signal123456789101112131415161718192021222324 __block int num = 0; RACSignal *signal = [[RACSignal createSignal:^RACDisposable *(i原创 2015-08-27 14:20:48 · 1142 阅读 · 0 评论 -
osx launchctl mongodb 自启动
mkdir -p ~/Library/LaunchAgentscp /usr/local/Cellar/mongodb/2.0.6-x86_64/homebrew.mxcl.mongodb.plist ~/Library/LaunchAgents/launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plistlaun转载 2015-05-21 15:21:44 · 825 阅读 · 0 评论 -
ReactiveCocoa系列-隐藏显示placehold
//创建textField获得焦点信号,当信号发生时返回@YES RACSignal *didBeginEditingSignal = [[self rac_signalForSelector:@selector(textFieldDidBeginEditing:) fromProtocol:@protocol(UITextFieldDelegate)] mapReplace:@Y原创 2015-02-25 21:38:00 · 1101 阅读 · 0 评论 -
Objective-C application starts
When an Objective-C application starts, it starts by running the function named main(). It doesn't have to be in the file "main.m" but that's how the Xcode wizard sets things up.Inside the wizard-转载 2012-03-20 18:36:45 · 921 阅读 · 0 评论 -
NSColor创建方法
ColorSync实用工具NSColor *rgb = [NSColorcolorWithDeviceRed:0.2471green:0.2471blue:0.2471alpha:1];原创 2012-04-28 14:59:09 · 2177 阅读 · 0 评论 -
点击应用程序左上角关闭 程序退出
把window的消息委托给AppDelegate,再到AppDelegate.m里加入以下函数- (BOOL)windowShouldClose:(id)sender//close box quits the app{ [NSApp terminate:self]; return YES;}原创 2012-04-28 15:21:34 · 1264 阅读 · 0 评论 -
NSView淡入淡出
淡入动画:[NSAnimationContext beginGrouping];[[NSAnimationContext currentContext] setDuration:2.0];[[theSuperview animator] addSubview:theView];[NSAnimationContext endGrouping];淡出动画:转载 2012-04-29 09:27:24 · 1265 阅读 · 0 评论 -
Cocoa下实现SplashScreen
#import @interface SplashWindow : NSWindow- (id)initWithSplashImage:(NSString*)imgfile;@end//SplashWindow.m#import "SplashWindow.h"@implementation SplashWindow- (id)initWithSplashImag原创 2012-05-03 13:07:28 · 1791 阅读 · 0 评论 -
会变色的背景透明NSButton
效果图://ColorTextButton.h#import @interface NSButton (ColorButton)- (void)setHoverColor:(NSColor *)textColor;- (void)setNormalColor:(NSColor *)textColor;- (void)setPushColor:(NSColor *)text原创 2012-05-03 13:48:43 · 4979 阅读 · 0 评论 -
NSImageView setImage失效?
今天碰到一个奇怪的问题,使用NSImageView setImage时,UI没有效果。后发现NSImageView的指针是空。后来发现AlbumViewCell *cell = [[AlbumViewCellalloc] initWithNibName:@"AlbumViewCell"bundle:nil];必须先调用一次[cell view],否则IB不会分配AlbumV原创 2012-05-07 15:15:41 · 1628 阅读 · 0 评论 -
拼接三幅图
Here is a function i whipped up that takes 1 image, and stretches just the middle...-(NSImage *)image:(NSImage *)image leftCapWidth:(float)leftWidth middleWidth:(float)middleWidth rightCapWidt转载 2012-05-20 22:31:22 · 1125 阅读 · 0 评论 -
Xcode 4.3 not presenting Autoresizing panel in Size Inspector
xcode 4.3 找不到size inspector,见下面方法http://stackoverflow.com/questions/9370072/xcode-4-3-not-presenting-autoresizing-panel-in-size-inspector转载 2012-11-27 14:25:34 · 678 阅读 · 0 评论 -
CFString convert char *
char * MYCFStringCopyUTF8String(CFStringRef aString) { if (aString == NULL) { return NULL; } CFIndex length = CFStringGetLength(aString); CFIndex maxSize = CFStringGetMaximumSizeForEnco转载 2012-12-31 10:18:59 · 969 阅读 · 0 评论 -
获取其它app的路径,以iPhoto为例
CFStringRef path = CFPreferencesCopyAppValue(CFSTR("LibraryPath"), CFSTR("com.apple.iPhoto"));翻译 2013-02-20 12:57:32 · 501 阅读 · 0 评论 -
ZXing CoocaPods被墙的问题
最近在一个项目里打算使用pod整合过的ZXing第三方源码,在pod update时会出现原创 2014-06-11 14:19:51 · 2333 阅读 · 0 评论 -
change swift compile version in xcode build settings
Build settings -> Swift Compiler - VersionYES swift 2.3NO swift 3.0原创 2016-07-14 10:20:48 · 991 阅读 · 0 评论