Swift 3.1正式發佈

Swift 3.1在今(2017/3/28)正式發佈!3.1是次要的更新版本,主要針對目前的標準函式庫做改善以及改進。
在IBM以及各社群成員的努力下,還包含了Swift on LINUX的更新。以及部份的Swift Package Manager更新~
此外在編譯器也加上預編譯Objective-C的功能,讓編譯速度加快~

更多訊息可參考原始文章
https://swift.org/blog/swift-3-1-released/

 

 

New Sequence protocol members

The Sequence protocol now has two new members:

protocol Sequence {
  // ...
  /// Returns a subsequence by skipping elements while `predicate` returns
  /// `true` and returning the remainder.
  func drop(while predicate: (Self.Iterator.Element) throws -> Bool) rethrows -> Self.SubSequence
  /// Returns a subsequence containing the initial elements until `predicate`
  /// returns `false` and skipping the remainder.
  func prefix(while predicate: (Self.Iterator.Element) throws -> Bool) rethrows -> Self.SubSequence
}

See more at: SE-0045: Add prefix(while:) and drop(while:) to stdlib

Availability by Swift version

Swift 3.1 extends the @availability attribute to use the version of Swift to indicate the lifecycle of a declaration. As an example, an API that is removed in Swift 3.1 would be written as:

@available(swift, obsoleted: 3.1)
class Foo {
  //...
}

See more at: SE-0141: Availability by Swift version

Improved numeric conversion initializers

Swift 3.1 adds a new family of conversion initializers to all numeric types that either complete successfully without loss of information or return nil.

See more at: SE-0080: Failable Numeric Conversion Initializers

Deprecation and replacement of UnsafeMutablePointer.initialize(from:)

The version of UnsafeMutablePointer.initialize(from:) that takes a Collection is deprecated in favor of a new method on UnsafeMutableBufferPointer that takes a Sequence, with a goal of improving memory safety and enabling faster initialization of memory from sequences.

See more at: SE-0147: Move UnsafeMutablePointer.initialize(from:) to UnsafeMutableBufferPointer

Improvements to the Linux implementation

  • Implementation of NSDecimal
  • Implementation of NSLengthFormatter
  • Implementation of Progress
  • Many improvements to URLSession functionality, including API coverage and optimized usage of libdispatch
  • Improved API coverage in NSArray, NSAttributedString and many others
  • Significant performance improvements in Data. See more details here
  • Improved JSON serialization performance
  • Memory leaks fixed in NSUUID, NSURLComponents and others
  • Improved test coverage, especially in URLSession

Package Manager Updates

Editable packages

Package dependencies are now stored in the tool-managed build directory by default, and a new swift package edit command allows users to “begin editing” on a package, moving it under the user’s control (into the Packages directory), exempting it from dependency updates, and allowing the user to commit and push changes to that package.

See more at: SE-0082: Package Manager Editable Packages

Version pinning

The version of each dependency you’ve used is now recorded in a Package.pins file, which can be checked in to share those versions with other users of your package; swift package pin and swift package unpin commands provide further control. The pinned versions of a package’s dependencies are fetched by default when resolving dependencies, but swift package update will re-resolve to the latest allowable dependency versions and update the pinfile.

See more at: SE-0145: Package Manager Version Pinning

Tools version

Packages can now specify the minimum version of the Swift tools that they require. This requirement can be edited with the swift package tools-version command and is recorded at the top of the Package.swift manifest. Package versions which require newer Swift tools than those in use will be ignored by dependency resolution, so packages can adopt new Swift features without breaking clients who are using older Swift tools. The minimum tools version required determines which Swift language version is used to interpret the Package.swift manifest, and which version of the PackageDescription API is available.

See more at: SE-0152: Package Manager Tools Version

Swift language compatibility version

Packages can now specify whether their sources are written in the Swift 3 or Swift 4 language version. If not specified, a default is inferred from the Package’s minimum Swift tools version.

See more at: SE-0151: Package Manager Swift Language Compatibility Version

Other Package Manager improvements

  • Package dependency resolution is now correct in cases where it could have resolved to incorrect dependency versions previously. Dependency cycles are now detected during a build, and incremental builds will rebuild fewer sources when possible.
  • swift test now supports running tests in parallel with the --parallel flag. swift build, swift test, and all swift package commands which resolve dependencies now support fetching those dependencies in parallel with the --enable-prefetching flag.

Documentation for the Swift Package Manager can be found in the repository.

Migrating to Swift 3.1

Swift 3.1 is source compatible with Swift 3.0. To help with moving to Swift 3.1 from earlier releases of Swift, Xcode 8.3 contains a code migrator that can automatically handle many of the need source changes. There is also a migration guide available to guide you through many of the changes — especially through the ones that are less mechanical and require more direct scrutiny.

Documentation

An updated version of The Swift Programming Language for Swift 3.1 is now available on Swift.org. It is also available for free on Apple’s iBooks store.

Platforms

Linux (Ubuntu 14.04, Ubuntu 16.04 and Ubuntu 16.10)

Official binaries for Ubuntu 14.04, Ubuntu 16.04 and Ubuntu 16.10 are available for download.

Apple (Xcode)

For development on Apple’s platforms, Swift 3.1 ships as part of Xcode 8.3.

Sources

Development on Swift 3.1 was tracked in the swift-3.1-branch on the following repositories on GitHub:

The tag swift-3.1-RELEASE designates the specific revisions in those repositories that make up the final version of Swift 3.1.

The swift-3.1-branch will remain open, but under the same release management process, to accumulate changes for a potential future bug-fix “dot” release.

Delphi 10 Berlin 在tabitem加上數字

tabbarcustom

interface
 
uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.TabControl, FMX.Controls.Presentation, FMX.Edit,
  FMX.EditBox, FMX.SpinBox, FMX.StdCtrls, FMX.Layouts, FMX.ListBox,
  FMX.NumberBox;
 
type
  TForm16 = class(TForm)
    TabItem1: TTabItem;
    TabItem2: TTabItem;
    BadgeItem: TTabItem;
    SpinBox1: TSpinBox;
    ToolBar1: TToolBar;
    Switch1: TSwitch;
    ListBox1: TListBox;
    ListBoxItem1: TListBoxItem;
    ToolLabel: TLabel;
    TabControl1: TTabControl;
    procedure BadgeItemPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
    procedure SpinBox1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Switch1Switch(Sender: TObject);
    procedure StepperUpClick(Sender: TObject);
  private
    FBadge: Integer;
    FShowBadge: Boolean;
    procedure SetBadge(const Value: Integer);
    procedure SetShowBadge(const Value: Boolean);
    { Private declarations }
  public
    { Public declarations }
    property Badge: Integer read FBadge write SetBadge;
    property ShowBadge: Boolean read FShowBadge write SetShowBadge;
  end;
 
var
  Form16: TForm16;
 
implementation
 
{$R *.fmx}
{$R *.iPhone55in.fmx IOS}
 
procedure DrawBadge(Canvas: TCanvas; const ARect: TRectF; const Text: string;
  const Color: TAlphaColor = TAlphaColorRec.Red);
const
  Padding = 2;
  HorzTextMargin = 6;
  VertTextMargin = 4;
var
  R: TRectF;
  TextSize: TSizeF;
  Brush: TBrush;
  BadgeRadius: Single;
begin
  Canvas.Font.Size := 12;
  // Measure text width
  TextSize := TSizeF.Create(Canvas.TextWidth(Text), Canvas.TextHeight(Text));
  // Calculate badge rect
  R := TRectF.Create(0, 0, HorzTextMargin * 2 + TextSize.Width, VertTextMargin * 2 + TextSize.Height);
  if R.Width < R.Height then
    R.Width := R.Height;
  // Position rect
  R := TRectF.Create(ARect.Right - R.Width, ARect.Top, ARect.Right, ARect.Top + R.Height);
  R.Offset(-Padding, Padding);
  // Draw badge
  BadgeRadius := R.Height / 2;
  Brush := TBrush.Create(TBrushKind.Solid, Color);
  try
    Canvas.FillRect(R, BadgeRadius, BadgeRadius, AllCorners, 1, Brush);
  finally
    Brush.Free;
  end;
  // Draw text
  Canvas.Fill.Color := TAlphaColorRec.White;
  Canvas.FillText(R, Text, False, 1, [], TTextAlign.Center, TTextAlign.Center);
end;
 
procedure TForm16.BadgeItemPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
begin
  if ShowBadge then
    DrawBadge(Canvas, ARect, FBadge.ToString);
end;
 
procedure TForm16.FormCreate(Sender: TObject);
begin
  FBadge := 1;
end;
 
procedure TForm16.SetBadge(const Value: Integer);
begin
  if FBadge  Value then
  begin
    FBadge := Value;
    BadgeItem.Repaint;
  end;
end;
 
procedure TForm16.SetShowBadge(const Value: Boolean);
begin
  if FShowBadge  Value then
  begin
    FShowBadge := Value;
    BadgeItem.Repaint;
  end;
end;
 
procedure TForm16.SpinBox1Change(Sender: TObject);
begin
  Badge := Trunc(SpinBox1.Value);
end;
 
procedure TForm16.StepperUpClick(Sender: TObject);
begin
  Badge := Trunc(SpinBox1.Value);
end;
 
procedure TForm16.Switch1Switch(Sender: TObject);
begin
  ShowBadge := Switch1.IsChecked;
end;
 
end.

原始資料:https://community.embarcadero.com/blogs?view=entry&id=9074

Delphi Berlin跨平台條件編譯(Conditional compilation)

Delphi Berlin可以在不同平台裝置上執行,那程式可以依不同平台裝置跑嗎?
答案是可行的~只要透過條件編譯就可以了 範例如下

   {$IFDEF MSWINDOWS}
   LABEL1.Text := Label1.Text + '(電腦版)';
   {$ENDIF}
   {$IFDEF ANDROID}
   LABEL1.Text := Label1.Text + '(安卓版)';

   {$ENDIF}
   {$IFDEF OSX}
   LABEL1.Text := Label1.Text + '(MAC版)';

   {$ENDIF}
   {$IFDEF IOS}
   LABEL1.Text := Label1.Text + '(IOS版)';

   {$ENDIF}

Delphi 10.1 Berlin新亮點 -FireUI Preview、ListView Designer、TAddressBook

感謝廖啟甫大哥通知晚上的 10.1 Berlin課程,雖然沒聽完!不過有聽到了幾個不錯的功能

一、TAddressbook元件,可以存取通訊錄

二、改進Style Designer

三、超酷的可以自訂ListView Items的設計功能

四、新的字型樣式

另外還有很酷的FireUI Preview功能。

看來Delphi一直很努力的追上這幾年的不足!

未命名 - 7 未命名 - 8 未命名 - 21 未命名 - 27 未命名 - 42 未命名 - 44 未命名 - 52 未命名 - 66

Delphi 10 Andriod/iOS開發小筆記(常常更新)

System.IOUtils.TPath.GetHomePath

Platform Sample path Path ID
Windows XP C:\Documents and Settings\<username>\Application Data CSIDL_APPDATA
Windows Vista or later C:\Users\<username>\AppData\Roaming FOLDERID_RoamingAppData
Mac OS X /Users/<username> NSUserDirectory
iOS Device /private/var/mobile/Containers/Data/Application/<application ID>
iOS Simulator /Users/<username>/Library/Developer/CoreSimulator/Devices/<Device ID>/data/Containers/Data/Application/<application ID>
Android /data/data/<application ID>/files Context.getFilesDir

For Android, set the Remote Path to assets\internal

For iOS, set the Remote Path to StartUp\Documents

// XE3 : DBJSON
// Seattle: System.JSON
var
  LJsonArr   : TJSONArray;
  LJsonValue : TJSONValue;
  LItem     : TJSONValue;
begin
   memo1.Lines.Clear;
   LJsonArr    := TJSONObject.ParseJSONValue(TEncoding.utf8.GetBytes(memo2.Lines.Text),0) as TJSONArray;
   for LJsonValue in LJsonArr do
   begin
      for LItem in TJSONArray(LJsonValue) do
        memo1.lines.add(Format('%s : %s',[TJSONPair(LItem).JsonString.Value, TJSONPair(LItem).JsonValue.Value]));
     memo1.Lines.Add('');
   end;
end;

參考: http://blogs.embarcadero.com/davidi/2013/11/23/43005/

借測Star TSP650II出單機撰寫行動POS

因為看到iChef列印電子發票的精美,所以找到台灣代理Star機器的大睿。不過因為借測的機器太過於熱門,其實是整整借了幾乎一整年才借到TSP650II這台出單機。今天收到後,就開始如火如荼的做測試,準備讓最後的Mobile POS系統中最後的電子發票、出單使用。

12832482_10153294891021541_2858365044269518802_n

10419968_10153294890961541_4466878536807084461_n
大睿股份有限公司 營業部 傅郁婷
TEL:+886-2-2763-2715
FAX:+886-2-2763-2192
台北市八德路四段245巷31號1樓

Delphi 10 在Android、iOS取得內部IP方式

在寫應用程式時,常常需要知道機器的IP是什麼!答案相當簡單~只要拉出IdIPWatch這個元件
然後透過 IdIPWatch裡的LocalIP這個屬性就可以了!
相較於以前要透過Winsock來撰寫!一整個方便多了~更重要的是可以同時在Windows/Mac跟iOS/Android上面跑~

連續30天30個Swift專案,學習Swift好資源

1-mvHITQUjZHgV1ZXsRaqKKQ
Sam Lu先前寫了一篇100 Days of Swift的文章,不過比較可惜的是並沒有開放原始碼出來讓大家一起學習。不過有位Allen Wong網友,效法Sam Lu做了30 Days Of Swift的計畫,更難能可貴的是他老兄開放了所有原始碼給大家參考。對有興趣自學Swift語言的朋友是很好的學習教材。
github cover

https://github.com/allenwong/30DaysofSwift
http://samvlu.com/