This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//sync呼叫 會在main queue執行 | |
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
for(int i=0;i<5;i++){ | |
NSLog(@"sync: %d %@",i, [NSThread currentThread]); | |
} | |
}); | |
//2018-04-30 16:42:57.905789+0800 NSTimer_NSRunLoop[4045:160977] sync: 0 <NSThread: 0x604000065540>{number = 1, name = main} | |
//2018-04-30 16:42:57.905875+0800 NSTimer_NSRunLoop[4045:160977] sync: 1 <NSThread: 0x604000065540>{number = 1, name = main} | |
//2018-04-30 16:42:57.905904+0800 NSTimer_NSRunLoop[4045:160977] sync: 2 <NSThread: 0x604000065540>{number = 1, name = main} | |
//2018-04-30 16:42:57.905929+0800 NSTimer_NSRunLoop[4045:160977] sync: 3 <NSThread: 0x604000065540>{number = 1, name = main} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface SerializeEncoder : NSObject | |
+ (BOOL) Encode : (NSObject *) encodeObject fileName:(NSString *) filename; | |
+ (NSObject*) Decode: (NSString *) filename; | |
@end | |
#import "SerializeEncoder.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Class必須實作NSCoding這個Protocol,裡面有兩個方法 | |
@protocol NSCoding | |
- (void)encodeWithCoder:(NSCoder *)aCoder; | |
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder; // NS_DESIGNATED_INITIALIZER | |
@end | |
@interface Connection : NSObject<NSStreamDelegate, NSCoding>{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//第一個方法是不宣告直接在implement內實作 | |
//另一個方法是在.m檔中使用Extension,方便管理 | |
#import "EggTimer.h" | |
//Extension | |
@interface EggTimer () | |
//外面看不見我 | |
- (void) canYouSeeMe; | |
@end | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//假設有一個class EggTimer | |
//其中有一個內部方法doYouKnowMe | |
//這個方法不想讓外部看見 | |
@interface EggTimer : NSObject{ | |
NSTimer *timer; | |
NSDate *startTime; | |
NSTimeInterval duration; | |
NSTimeInterval elapsedTime; | |
} | |
@property id delegate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Globalization; | |
using System.IO; | |
using System.Linq; | |
using System.Reflection; | |
using System.Text; | |
namespace MyProject | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
參考自http://www.digitallycreated.net/Blog/61/combining-multiple-assemblies-into-a-single-exe-for-a-wpf-application | |
在最底部增加這幾行 | |
<Target Name="AfterResolveReferences"> | |
<ItemGroup> | |
<EmbeddedResource Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.Extension)' == '.dll'"> | |
<LogicalName>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</LogicalName> | |
</EmbeddedResource> | |
</ItemGroup> | |
</Target> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DllImport("kernel32.dll")] | |
public static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max); | |
public void FlushMemory() { | |
GC.Collect(); | |
GC.WaitForPendingFinalizers(); | |
if (Environment.OSVersion.Platform == PlatformID.Win32NT) { | |
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//winform | |
//在不同執行續下想要呼叫前端物件時可以使用invoke()來切換當前執行續 | |
control.invoke() | |
//使用invoke()是同步執行,執行完invoke()中程式內容後才會接著執行下面的程式 | |
control.BeginInvoke() | |
//使用BeginInvoke()是非同步執行,兩邊程式都會一起執行 | |
control.EndInvoke() |
NewerOlder